input problem

M

MC felon

hi.
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 (after it asks,
"save file?"). 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top