Yet your code above is not safe.
Originally Posted by Therry
Using spaces may work in your current context, but may fail later on when you try to use it in a different project. Say for file I/O as an example.
You should study the use of getline thoroughly. It can be a powerful asset with input and file I/O.
In your situation you should take the input as a single line as you have with getline.
then parse the input in a function
getline( std::ifstream, std::string, Delimiter Character );
// Eynhallow.cpp : Defines the entry point for the console application.
std::string FormatString(const std::string& Src)
std::string::const_iterator it = Src.begin();
while ( it != Src.end() )
/* With this switch statement you can add other characters that you want removed from your strings */
switch ( (int)(*it) )
ret_val += (*it);
int main(int argc, char* argv)
/* Get Input from user */
std::getline(std::cin, original, '\n');
/* Make a formatted string from the original */
std::string Test = FormatString(original);
std::cout << "Original String: " << original << '\n';
std::cout << "FormatString(): " << FormatString(original) << std::endl;