fstream problem, please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    srand((unsigned)time(0));
    int random=rand() % 3 + 1;
    SetConsoleTitle("PotatoOS v1.1");
    string input;
    string output;
    bool word(char *Filename,int number);
    std::fstream readFile; //for reading from the file
    ofstream createFile; //for making the file
    createFile.open("Brain.txt"); //made the file
    createFile<< "whats up?\ni am happy\nyou seem nice"; //what is in the file
    createFile.close(); 
    start:
    {
    readFile.open("Brain.txt"); //initializes the file
    for(int i=0; i<random; i++) getline(readFile,output); //gets a random line
    cout<< ""<<output<<"\n"; //prints the line
    getline(cin, input); //gets user input
    readFile<< ""<<input<<""; //supposed to save input to file but doesn't
    readFile.close(); //closes the file 


I do not understand why this isn't working. It is supposed to take the "input" and save it to the file "Brain.txt". Everything works except that it doesn't update the file to contain "input".
try replace
readFile<< ""<<input<<"";

with
readFile<< input<< '\n';
Topic archived. No new replies allowed.