File formatting.

I'm experimenting with writing to files and I've created a loop that simple continues to accept user input until a key word is used then it ends the loops and the file is saved and closed etc.
However when I open the file there's no spaces in it. Is there a way I can stop the system from removing the spaces?

The code I'm using is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void filewriteproc(){
    string userlinewrite;
    ofstream userwrittenfile;

    userwrittenfile.open ("UWF01.txt", ios::ate);

    cout << "Begin log: ";
    do {

    cin >> userlinewrite;

    userwrittenfile << userlinewrite;
    }
    while (userlinewrite != "EndUserFileWrite");



    userwrittenfile.close();
}
That's because your using cin >> on a string. It extracts input until a space or newline. If the user puts a space in their string, only the first part is read. Do this instead:

 
getline(cin, userlinewrite);
Last edited on
Thank-you both, Modshop for the nice fix.
and Catfish for the good info! :)
Topic archived. No new replies allowed.