i need assistance in completing the code

toader's Avatar, Join Date: Jun 2009
Newbie Member
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.

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/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";
    }
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
(1) What do you mean by "complete my code" ?? Tell us how it is incomplete and what you would like to add, how you would like it to be added etc.. etc.. Please be clear.\

(2) The texts are not in English. For example, cout << "Ce cuvint doritzi sa modificatzi? : ";
So, it's hard to find what your program wants to do. (although I can make something out of the code)
0
toader's Avatar, Join Date: Jun 2009
Newbie Member
Quote:
Originally Posted by SaswatPadhi View Post
(1) What do you mean by "complete my code" ?? Tell us how it is incomplete and what you would like to add, how you would like it to be added etc.. etc.. Please be clear.\

(2) The texts are not in English. For example, cout << "Ce cuvint doritzi sa modificatzi? : ";
So, it's hard to find what your program wants to do. (although I can make something out of the code)
1.
it change only one word

example.txt = George is good boy.
example2.txt = * free *
Console: What word u want to change?
Me: George
Constole: Write new word for change.
Me: Djon

example2.txt = Djon is good boy.

i need to can change more 2 words. like this:

example.txt = George is good boy.
example2.txt = *free*
Console: What word u want to change?
Me: George good
Constole: Write new word for change.
Me: Djon bad

example2.txt = Djon is bad boy.




2.
1 question: What word u want to change?
2 question: Write new word for change.
3 text: error
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
That's a better description of the problem.
How far have you got and where are you stuck?
Has it occurred to you simply to loop over the input words one at a time and use the existing code to replace that word? Then just repeat until you have no words left to replace.