You need to rethink your logic.
30 31 32 33
|
for (char &ch : punct_chars)
{
index = input.find(ch);
}
|
Here, you loop over every character in
punct_chars. Each time you find one of those characters in your input, you overwrite
index with the index of the character you've just found. So, when your loop ends, you have a single value of
index, which is the index of the last punctuation character you found.
In this case, that character is
'
, because that comes later in
punct_chars than
-
. So you exit that loop with index set to the position of that character.
Then you have a second loop:
34 35 36 37 38 39 40 41 42 43 44 45
|
for (size_t i = 0; i < input.size(); ++i)
{
cout << input[i];
if (input[i] == input.find('"')) // With the example string you're using, this is always false
{
// ...
}
else
{
input.erase(index);
}
}
|
Nowhere in your loop do you ever change the value of
index. So, for every iteration of your loop, you're erasing the character at the same position in the input. I'm sure you can see how this results in erasing every character in your string from
'
onwards?
EDIT: Also, your code would look nicer when posted here, if you configured whatever IDE/editor you're using so that, when it indents your code, it uses spaces rather than TAB characters.