помогите закончить код

This is a discussion on помогите закончить код within the C++ Programming forums, part of the General Programming Boards category; So I wrote this code, it changes one word to another .. but I can not do so that he ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    4

    Exclamation cant finish code((

    So I wrote this code, it changes one word to another .. but I can not do so that he can change more words: (

    thank you very much

    Code:

    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;
    }
    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
    toader is online now
    Last edited by toader; 06-20-2009 at 12:03 AM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Если вы хотите изменить слово между другими символами, то необходимо построить слово для сравнения путем рассматривать каждое письмо от входного сигнала. Можете вы написать английскую язык, если вы пожалуйста?
    Last edited by Sebastiani; 06-19-2009 at 08:15 PM. Reason: lost in the translation
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    892
    I couldn't agree with the two of you more.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    I can't find these keys on my keyboard

    since when did they make a leetspeek font?
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Interesting... Babelfish was able to translate Sebastiani's message into readable English, but when it translates toader's message, it makes no sense.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Suggestions:
    Code:
        while (!finp.eof() && !(finp >> word).fail())
    =>
    Code:
        while(finp >> word)
    Code:
        std::string word;
        string m,n;
    =>
    Code:
    std::string word;
    std::string m, n;
    or
    Code:
    string word;
    string m, n;
    Other than that, I don't know what you're asking, so I can't help.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by cpjust View Post
    Interesting... Babelfish was able to translate Sebastiani's message into readable English, but when it translates toader's message, it makes no sense.
    probably because Sebansitani used a translator
    Last edited by ಠ_ಠ; 06-19-2009 at 10:24 PM. Reason: read the next post
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    No doubt. See Sebastiani's edit message.

    I'm guessing the OP knows a little English from the source code. So: try to post in English. No matter how bad it is, it's probably more useful to people reading your post than a language they can't understand. Or hope that a few people know . . . whatever language that is.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by dwks View Post
    . . . whatever language that is.
    Based on the alphabet, it's Russian, or something very close to Russian.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by cpjust View Post
    Based on the alphabet, it's Russian, or something very close to Russian.
    Russian might be the most common but it's by far not the only language written in Cyrillic:

    Languages using Cyrillic - Wikipedia, the free encyclopedia

    That said, my (Russian) wife could translate it. It must be Russian
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Registered User
    Join Date
    Jun 2009
    Posts
    4
    edit
    Last edited by toader; 06-20-2009 at 12:02 AM.

  12. #12
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    You just need to split the input strings into two arrays (or vectors) of strings, and then during the comparison, loop through the first list (the "old" names), keeping track of the current index, and if a match is found, use that index fetch the appropriate substitute from the second list (the "new" names).

    EDIT:
    Note: an std::map might be a better candidate for this than a vector.
    Last edited by Sebastiani; 06-20-2009 at 12:01 AM.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  13. #13
    Registered User
    Join Date
    Jun 2009
    Posts
    4
    Quote Originally Posted by Sebastiani View Post
    You just need to split the input strings into two arrays (or vectors) of strings, and then during the comparison, loop through the first list (the "old" names), keeping track of the current index, and if a match is found, use that index fetch the appropriate substitute from the second list (the "new" names).

    EDIT:
    Note: an std::map might be a better candidate for this than a vector.


    can u show me how i can do all this?? (

  14. #14
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    >> can u show me how i can do all this?? (

    Our policy here is not to do your homework for you. Post the code you have tried and we will try to point you in the right direction.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21