toader2 Posted June 22, 2009 Share Posted June 22, 2009 Hello,i need assistance in completing the code, I do not have enough experience, anyone can complete it? it is at one point change 1 word in new and need to able to change more than words .. Thank you very much for the former. #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/example2.txt"); if (!finp || !fout) { std::cout << "Error opening file\n"; 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; std::string m,n; cout << endl; cout << endl; cout << "Ce cuvint doritzi sa modificatzi? : "; getline(std::cin, m); cout << "Cu ce cuvint doritzi sal modificatzi? : "; 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 << "Asha cuvint nu exista in propozitzia data!!!!!!\n"; } Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted June 23, 2009 Veteran Share Posted June 23, 2009 I'm sorry, I don't understand what you're trying to do. Link to comment Share on other sites More sharing options...
0 BGM Posted June 23, 2009 Share Posted June 23, 2009 please rephrase the question and or translate the lines in the code into english cheers! :p Link to comment Share on other sites More sharing options...
0 ViZioN Posted June 23, 2009 Share Posted June 23, 2009 I think he's trying to implement a mechanism that looks for certain words in file A and if it finds them it outputs them to file B. Maybe... :unsure: Link to comment Share on other sites More sharing options...
Question
toader2
Hello,i need assistance in completing the code, I do not have enough experience, anyone can complete it?
it is at one point change 1 word in new and need to able to change more than words .. Thank you very much for the former.
#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/example2.txt"); if (!finp || !fout) { std::cout << "Error opening file\n"; 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; std::string m,n; cout << endl; cout << endl; cout << "Ce cuvint doritzi sa modificatzi? : "; getline(std::cin, m); cout << "Cu ce cuvint doritzi sal modificatzi? : "; 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 << "Asha cuvint nu exista in propozitzia data!!!!!!\n"; }Link to comment
Share on other sites
3 answers to this question
Recommended Posts