string replace
string aword;
char c;
string in_file_name = "Slim Shady.txt";
ifstream fin;
fin.open(in_file_name.c_str());
if(!fin)
{
cout %26lt;%26lt; endl
%26lt;%26lt; "could not open " %26lt;%26lt; in_file_name %26lt;%26lt; flush;
cin.get();
return -1; //Can't carry on if the file is not open
}
string out_name = "";
out_name = out_name + "clean_" + in_file_name;
ofstream fout;
fout.open(out_name.c_str());
if(!fout)
{
cout %26lt;%26lt; endl
%26lt;%26lt; "could not open " %26lt;%26lt; out_name %26lt;%26lt; flush;
cin.get();
return -1; //Can't carry on if the file is not open
}
//Ask user for foul_word
if (!fout)
{
cout%26lt;%26lt; " input foul_word"%26lt;%26lt;endl;
cin%26gt;%26gt; "foul_word"%26gt;%26gt;endl;
cin.get();
return -1;
//make expletive using foul_word
//change foul_word to upper case
string expletive= makeexpletive(foulword);
foulword toupper(foulword);
fin %26gt;%26gt; aword;
while(!fin.fail())
{
string temp= toupper aword
int where = temp.find (0,foulword);
if(where!=-1)
{
}
aword.replace
string temp= replace( foulword, string temp(), s2 ); cout %26lt;%26lt; s %26lt;%26lt; endl
//create temp string that is tuupper version of aword
//if foul_word is in temp then replace foul_word with expletive in aword
aword.replace( where,foulword.length(),expletive);
fout %26lt;%26lt; aword;
fin.get( c );
while(isspace(c))
{
c = toupper(c);
fout %26lt;%26lt; c;
//in case the end of file is a space
if(fin.fail())
{
break;
}
fin.get(c);
}
aword = "";
aword = aword + c;
string next_word;
fin %26gt;%26gt; next_word;
aword = aword + next_word;
}
//cin.get();
fin.close();
fout.close();
return 0;
}
string toupper(string s)
{
string temp = "";
for(int i=0; i%26lt;s.size(); i++)
{
char c = toupper(s[i]);
temp = temp + c;
}
return s;
}
string makeexpletive(string s)
{
char face;
string temp ="";
srand(time(0));
for(int i = 0; i %26lt; s.length(); i++)
{
face = rand() % 5 + 1;
switch(face)
{
case 1 : temp = temp + '$'; break;
case 2 : temp = temp + '%26amp;'; break;
case 3 : temp = temp + '?'; break;
case 4 : temp = temp + '*'; break;
case 5 : temp = temp + '@'; break;
}
}
return temp;
}
C++ code to replace words in a document, keep getting run error?
Telling us what Run Error you're getting might help. Besides the fact that you don't even say what compiler you're using, few people here want to take the time to cut-and-paste all your code into our compiler, then work through getting it to compile and start running to find out what it MIGHT be.
Sorry that's not directly helpful, but it's good advice.
Reply:hey dude, u missing some semicolons maybe. at least i spot one.
string replace //u forgot to put a semi colon here
and did u write
#include %26lt;iostream%26gt;
#include %26lt;iomanip%26gt;
#include %26lt;fstream%26gt;
#include %26lt;string%26gt;
etc etc.??
Reply:(what%26gt; the}
Run...hell=you
switch....
talking@@[dd}
((0))
about.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment