2

So I want to be able to open up the file after the console closes and be able to continue adding to the file.

int main(){
    string inputWord;
    ofstream theFile("Info.txt");
    cout << "Type Word or Sentence: ";

    while(getline(cin,inputWord)){
        cout << "Type Word or Sentence: ";
        theFile << "Word or Sentence: " << inputWord;
        theFile << "(Regular Value): " << ch2n(inputWord) << endl;
        theFile << "(Other Value): " << char2num(inputWord) << endl;
        theFile << "(Sum): " << ch2n(inputWord) + char2num(inputWord) << endl;
        theFile << "(Difference): " << ch2n(inputWord) - char2num(inputWord) << endl;
        theFile << "(Total): " << ch2n(inputWord) + (ch2n(inputWord)+char2num(inputWord)) + (ch2n(inputWord)-char2num(inputWord)) + char2num(inputWord) << endl << endl;

        if(inputWord == "")return 0;
    }
}
Kilo King
  • 189
  • 1
  • 4
  • 14

2 Answers2

5

You have to open the file stream in append mode:

std::ofstream out("Info.txt", std::ios_base::app);
//                            ^^^^^^^^^^^^^^^^^^
David G
  • 94,763
  • 41
  • 167
  • 253
0

http://www.cplusplus.com/reference/fstream/fstream/open/

at here there is an example also.

// fstream::open / fstream::close
#include <fstream>      // std::fstream

int main () {

  std::fstream fs;
  fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);

  fs << " more lorem ipsum";

  fs.close();

  return 0;
}
karakale
  • 126
  • 11