getline problem

Why this program cannot record to text file the second inputted data. only the were stored in the text file...please help

#include<iostream>
#include<fstream>
#include<string>
#include<sstream>

using namespace std;

int main()

{

string add,name;

ofstream outData("test.txt",ios::app);
cout << "tie example: " << endl;
cout << "this is inserted into cout. " << endl;

cout<<"Name: ";
getline(cin, name);

cout<<"Address: ";
getline(cin, add);

outData << name;
outData << add << endl;

outData.close();
return 0;
}
Last edited on
The code is fine. There must be another issue.
Try using cin.sync() before the second cout, if you do not get the chance to input the address
tnx @Aceix...i made it...
Yeah always ready to help......hahaa
use cin.ignore() is better . to clear the buffer

cin.ignore(); //clear the buffer from user input
Topic archived. No new replies allowed.