Add more words to a text file in C++ -


i'm creating program writes user inputted words text file has other words begin with. this:

"words.txt" apples oranges bananas 

what wanna add other words list , output words on screen. wrote program won't input user specified word.

int main(){      ifstream fin("wordlist.txt");      if (fin.fail()){         cerr << "error opening file" << endl;         system("pause");         exit(1);     }      vector<string> wordlist;     string word;      string out_word;      cout << "please enter word: ";     cin >> out_word;      fin >> out_word;    //trying input user specified word      //this inputs words     while (!fin.eof()){         fin >> word;         wordlist.push_back(word);     }      //this outputs words on screen     (int = 0; < wordlist.size(); i++){         cout << wordlist[i] << endl;     }      fin.close();     system("pause");     return 0; } 

a simple way handle this:

  1. read in file vector
  2. ask user words , add vector
  3. write out words of vector out-stream.

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -