So I wrote this code, it changes one word to another .. but I can not do so that he can change more words: (
thank you very much
Code:
i work on this code more 3 days and cant finish it ((((Code:#include <iostream> #include <fstream> #include <string> #include <iterator> #include <algorithm> using namespace std; int main() { string line; ifstream finp("./src/example.txt"); ofstream fout("./src/vasea-out.txt"); if (!finp || !fout) { std::cout << "Error opening file" << std::endl; return 1; } copy(istream_iterator<char>(finp >> noskipws), istream_iterator<char>(), ostream_iterator<char>(cout)); finp.clear(); finp.seekg(0); finp.setf(ios_base::skipws); std::string word; string m,n; cout << endl; cout << "What word u want to chenge?? :" <<endl; getline(std::cin, m); cout << "Write new word? :" <<endl; getline(std::cin, n); bool found = false; while (!finp.eof() && !(finp >> word).fail()) { if (word == m) { fout << n << " "; found = true; } else fout << word << " "; } if (!found) cout << "Can't find this word!!!!!!" << endl; }
need to do like this:
example.txt = Jorge is good boy
vase-out.txt =
Start code:
code show: Jorge is good boy
code show: What word u want to chenge??
we write: Jorge good
code show: Write new word?
we write: Mike bad
Finish code.
vasea-out = Mike is bad boy
how to do this?? plzz help
toader is online now