Reading in a string ignoring all spaces?
1 2 3
|
string infix;
cout << "Enter infix expression : ";
cin >> infix;
|
This is what I have. However, I want it to omit all spaces.
If I were to type in 2 + 3, I want it to only read 2+3 into the string, not 2 + 3
Thanks :)
Get it all into a string then use erase and remove members of string to remove all the spaces.
Last edited on
figured it out...
1 2
|
#include<ctype.h>
#include<algorithm>
|
1 2 3 4
|
string infix;
cout << "Enter infix expression : ";
getline(cin, infix);
infix.erase(remove_if(infix.begin(), infix.end(),::isspace), infix.end());
|
Topic archived. No new replies allowed.