Jump to content

c++ how to remove spaces in a string??

Pachuca

I'm writing some code and I was wondering if there's an argument or parameter used with string to filter out things like spaces. For example if I typed input as "red apples"  when I try to store it into a string variable it doesn't work because of the space. Would a string array work in this case?

Link to comment
Share on other sites

Link to post
Share on other sites

Using "std::cin >> " will only read up to the first whitespace character. To read an entire line you should use std::getline(cin, string) which will by default read up to a newline character but you can also set whatever delimiter you want.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×