View Full Version : help plz to finish code

06-20-2009, 02:21 AM
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

#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));
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 :(

06-20-2009, 02:21 AM

06-20-2009, 05:17 AM
It's been a while since I've looked at any C type code, but I think your problems are:

getline(std::cin, m);
getline(std::cin, n);

These only read in one variable each - or one word each.

while (!finp.eof() && !(finp >> word).fail())
if (word == m)

This only loops through the input phrase once and only makes one replacement.

06-20-2009, 06:01 AM
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?

it career
06-22-2009, 08:52 AM
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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum