M
MC felon
hello all.
I am back again. i have a slight problem with input here. here's the
code compiled under the GNU standard c++ compiler. somehow,
getline(std::cin, string h) doesn't seem to be working. can anybody
please help me know what's happening and why it's happening? thanks.
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
using namespace std;
void save();
class std_employee
{
private:
int number;
string name;
string ans;
public:
std_employee()
{ system("CLS"); }
void disp_data()
{
cout<<"\nthe employee's name is: ";
cout<<name<<endl;
cout<<"\nthe employee's number is: ";
cout<<number<<endl;
}
void take_data()
{
cout<<"\nenter the employee name: ";
getline(cin,name);
cout<<"\nenter the employee's number: ";
cin>>number;
}
void store()
{
cout<<"\n\nsave file?"<<endl;
getline(cin,ans);
if(strcmp(ans,"yes") == 0)
{
save();
}
else
{
exit(0);
}
save();
}
};
void save()
{
std_employee emp1;
string file;
cout<<"save as?: ";
getline(cin,file);
ofstream out("test.txt");
out<<"it aint wurking";
out.close();
cout<<"\nsaved successfully.\n"<<endl;
}
int main()
{
std_employee emp1,*ptr;
ptr = &emp1;
ptr->take_data();
ptr->disp_data();
cin.get();
ptr->store();
return 0;
}
cheers
I am back again. i have a slight problem with input here. here's the
code compiled under the GNU standard c++ compiler. somehow,
getline(std::cin, string h) doesn't seem to be working. can anybody
please help me know what's happening and why it's happening? thanks.
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
using namespace std;
void save();
class std_employee
{
private:
int number;
string name;
string ans;
public:
std_employee()
{ system("CLS"); }
void disp_data()
{
cout<<"\nthe employee's name is: ";
cout<<name<<endl;
cout<<"\nthe employee's number is: ";
cout<<number<<endl;
}
void take_data()
{
cout<<"\nenter the employee name: ";
getline(cin,name);
cout<<"\nenter the employee's number: ";
cin>>number;
}
void store()
{
cout<<"\n\nsave file?"<<endl;
getline(cin,ans);
if(strcmp(ans,"yes") == 0)
{
save();
}
else
{
exit(0);
}
save();
}
};
void save()
{
std_employee emp1;
string file;
cout<<"save as?: ";
getline(cin,file);
ofstream out("test.txt");
out<<"it aint wurking";
out.close();
cout<<"\nsaved successfully.\n"<<endl;
}
int main()
{
std_employee emp1,*ptr;
ptr = &emp1;
ptr->take_data();
ptr->disp_data();
cin.get();
ptr->store();
return 0;
}
cheers