Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation help plz to finish code

    writed this code.. but need to can change more 1 words.. how to do this? if i write 1 word that change.. but cant do 2 or more words((( help plz

    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;
    }

    plz help do do this ((( i work on this code more 3 days and cant finish it ((((

    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
    Last edited by toader; 06-20-2009 at 02:23 AM.

  • #2
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    edited

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It's been a while since I've looked at any C type code, but I think your problems are:

    Code:
    getline(std::cin, m);
    getline(std::cin, n);
    These only read in one variable each - or one word each.

    Code:
        while (!finp.eof() && !(finp >> word).fail())
        {
            if (word == m)
    This only loops through the input phrase once and only makes one replacement.
    Last edited by tomws; 06-20-2009 at 03:16 PM. Reason: sp
    Are you a Help Vampire?

  • #4
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    This looks like a homework assignment. To all respondents, please be very careful not to provide help that goes beyond limiting it to just the problem area of the code. We've had a few suspicious "Homework type" assignments posted on CF lately, with some members basically helping write the entire assignment for him/her. That's helping these individuals cheat. tomws' response is fine BTW.

    When in doubt on how much help goes too far, just put yourself in the shoes of a teacher confronted with a student asking for help on his/her assignment- how much help becomes too much?
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.

  • #5
    Banned
    Join Date
    Jun 2007
    Location
    Web Designer
    Posts
    321
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Put the words read in a vector of strings, search strings to replace in the vector and replace it , you have got an easy homework.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •