Well after all to write a function is too hard for me yet, i gotta try to learn it still later though.
So i added a third loop to the program but its not working, i dont understand why.
It finds two "tom tom" but wont find any if i put three "tom tom tom" in the file.
Code:
int main () {
vector<string> myvector;
string::iterator it;
string::iterator it2;
string::iterator it3;
size_t found;
string str;
string str2 = "tom";
ifstream file ("1.txt");
for (int i = 0; getline(file, str); i++)
{
myvector.push_back(str);
it = search (myvector[i].begin(), myvector[i].end(), str2.begin(), str2.end()); // search
if (it != myvector[i].end())
{
myvector[i][distance(myvector[i].begin(),it)] =
toupper(myvector[i][distance(myvector[i].begin(),it)]); // uppercase first found
it2 = search (it, myvector[i].end(), str2.begin(), str2.end()); // continue searching
if (it2 != myvector[i].end())
{
myvector[i][distance(it,it2)] =
toupper(myvector[i][distance(it,it2)]); // uppercase second found
it3 = search (it2, myvector[i].end(), str2.begin(), str2.end()); // continue searching
if (it3 != myvector[i].end())
{
myvector[i][distance(it2,it3)] =
toupper(myvector[i][distance(it2,it3)]); // uppercase third found
}
else
cout << myvector[i] << endl;
}
else
cout << myvector[i] << endl;
}
else
cout << myvector[i] << endl;
}
file.close();
system("pause");
return 0;
}