Shouldnt "replace()" find and replace every instance of str with str2 in the vector?
So why does it replace only one "tom" on one line and not several?
I guess it has something to do with getline().
But in the example with an "int" it finds several instances of the same number in one line.
http://www.cplusplus.com/reference/a...m/replace.html
So i dont understand whats the problem. Thanks!
Code:int main() { vector<string> myvector; vector<string>::iterator it; string str = "tom"; string str2 = "Tom"; string str3; ifstream file ("1.txt"); while (getline(file, str3)) { myvector.push_back(str3); } replace(myvector.begin(), myvector.end(), str, str2); for (it = myvector.begin(); it != myvector.end(); it++) cout << *it << "\n"; file.close(); system("pause"); }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.