| | |
Finding and Replacing Strings
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2003
Posts: 2
Reputation:
Solved Threads: 0
I kinda have a problem. What i'm tryin to do is read a couple or lines or so from a text file and then replace all the gender pronouns ie(he, she, him, her) and replace those with gender neutral ones. The problem i'm having is trying to find all the gender pronouns and replacing them Her is a example of my code so far. Any help would be a God send.
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
ifstream gender;
gender.open("Proj1.txt");
string str1="", str2=" he", str3=" she", str4=" him", str5=" her",str;
int pos =0;
if (gender.is_open())
{
while(!gender.eof())
{
getline(gender, str1);
pos=str1.find(str2,0);
cout<<str1.replace(pos, 3, " he or she"<<endl;
getline(gender, str1);
}
}
gender.close();
return 0;
}
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
ifstream gender;
gender.open("Proj1.txt");
string str1="", str2=" he", str3=" she", str4=" him", str5=" her",str;
int pos =0;
if (gender.is_open())
{
while(!gender.eof())
{
getline(gender, str1);
pos=str1.find(str2,0);
cout<<str1.replace(pos, 3, " he or she"<<endl;
getline(gender, str1);
}
}
gender.close();
return 0;
}
![]() |
Similar Threads
- Finding Specific Strings in Another Strings [not charindex] (MS SQL)
- very strange string behaviur.. (C)
- Finding the union of two strings (C++)
- Help to create a unique forum (PHP)
Other Threads in the C++ Forum
- Previous Thread: Error Linking KeyLogger.exe
- Next Thread: Canvas and shape problem
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets




