c++ fstream

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();
}
if you want it in one file why are you putting them into two different text files?
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
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;
}
thanks man.
now i know where my mistake.
Topic archived. No new replies allowed.