I am writing a program that has to analyze a string and then if there's a contracted form (e.g. "don't") I have to transform it in "do not". To do that, reading cplusplus.com Reference, I have written a function that should help me to solve this issue. When I am trying to call the function I get a run-time-error of type "out-of-range memory" I guess I get wrong something with iterators but I am not sure. This is my function:
void remove_punct()
{
while (true)
{
cout << endl;
cout << "Type what you want and I will let punctuation disappear:";
string buffer;
getline(cin, buffer);
stringstream ss{ buffer };
for (string s; ss >> s;)
{
s = remove_trunc(s);
}
for (string s; ss >> s;)
{
for (char& c : s)
{
if (ispunct(c) && c != '"') c = ' ';
}
cout << s << " ";
}
}
}
For now I am trying to do something general so that every suffix "-n't" should be translated in " not". Just this for the moment! Without considering any other kind of contracted forms. That's the idea! It is part of an exercise and this was the request :)