Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   i need assistance in completing the code (http://www.go4expert.com/forums/i-assistance-completing-code-t18146/)

toader 22Jun2009 12:43

i need assistance in completing the code
 
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";
    }


SaswatPadhi 22Jun2009 13:02

Re: i need assistance in completing the code
 
(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)

toader 22Jun2009 14:42

Re: i need assistance in completing the code
 
Quote:

Originally Posted by SaswatPadhi (Post 50258)
(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

xpi0t0s 22Jun2009 20:37

Re: i need assistance in completing the code
 
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.


All times are GMT +5.5. The time now is 04:13.