c++ fstream
Apr 21, 2013 at 5:52am UTC
hi
im kind of new to c++.
can anyone help me with this code?
i want to enter the data into 1 txt file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int main()
{
ofstream outname;
cout<<"name?" <<endl;
string name;
getline(cin,name);
outname.open("name.txt" );
outname<<name;
ofstream outid;
cout<<"id?" <<endl;
string id;
getline(cin,id);
outid.open("id.txt" );
outid<<id;
outname.close();
outid.close();
}
Apr 21, 2013 at 6:08am UTC
if you want it in one file why are you putting them into two different text files?
Apr 21, 2013 at 6:15am UTC
i try to put it in 1 file but the 2nd data won't store it in the the txt file.
i don't know whether i 'm using the correct way or not.
try to google it before but cannot find the solution.
hope u can help me.
thanks
Apr 21, 2013 at 6:25am UTC
how about
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
string name, id;
ofstream outname;
cout<<"name?" <<endl;
getline(cin,name);
cout<<"id?" <<endl;
getline(cin,id);
outname.open("name.txt" );
outname<<name;
outname<<id;
}
Apr 21, 2013 at 6:56am UTC
thanks man.
now i know where my mistake.
Topic archived. No new replies allowed.