Well, the thing which is missing from the above code is somewhere to put the result. Hence the difficulty on line 19.
How about adding at line 5
string resultString;
Then instead of using
cout at line 14, add the current character to
resultString.
That should do the trick.
(there are at least three ways to add a character to the end of a string, using
+= or
append() or
push_back(). I'd use the first option).
see
http://www.cplusplus.com/reference/string/string/
There are a few things that are either wrong or bad practice with the above code,
tempString and
tempString2 are badly-named, they are not strings at all, and should not be named as such.
The variable p in the for loop is of type
char, when it would be much better to use an
int. The use of char p means the code will fail if the input string is longer than 127 characters.