1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

i need assistance in completing the code

Discussion in 'C++' started by toader, Jun 22, 2009.

  1. toader

    toader New Member

    Joined:
    Jun 22, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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";
        }
    
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    (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)
     
  3. toader

    toader New Member

    Joined:
    Jun 22, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page