Я не могу понять, почему этот код не работает с segfault:
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, char** argv) {
map <string, string> temp;
map <string, string>::iterator it;
S
string text = "";string thatChange = "";string whatChange = "";
getline (cin, text);
while (true)
{
getline (cin, thatChange);
if (thatChange == "-1")
break;
getline (cin, whatChange);
temp.insert(pair <string, string> (thatChange, whatChange));
}
for (int i = 0; i < temp.size(); i++)
{
string thatChange = it->first ; // thatChange
string whatChange = it->second; // whatChange
it++;
int index = text.find(thatChange);
text.erase(index, thatChange.size());
text.insert(index, whatChange);
}
cout << "text\n"<< text;
return 0;
}
UPD: отладчик говорит:
No source available for "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() at 0x7ffff7b75928"