Remove space from input

E

eli m

Hi, I have a program where the input involves space sometimes and i want to remove the spaces from the input. For example: if they type in hello world, then it would receive helloworld. How would i do this? Thanks in advance.
 
Ö

Öö Tiib

Hi, I have a program where the input involves space sometimes and i want to remove the spaces
from the input. For example: if they type in hello world, then it would receive helloworld. How
would i do this? Thanks in advance.

You 'find_first_of' space and then 'erase' it until there are none.
 
J

James Kanze

Hi, I have a program where the input involves space sometimes
and i want to remove the spaces from the input. For example:
if they type in hello world, then it would receive helloworld.
How would i do this? Thanks in advance.

Just use >> on strings, and then concatenate them.
 
E

eli m

Just use >> on strings, and then concatenate them.Can you explain in more detail please?
 
E

eli m

If you read strings from your input stream using operator>> the

whitespace between the strings is not included in the strings.



If you then join the strings together you will have removed the whitespace.



"abc def ghi" becomes the three strings "abc" "def" "ghi" which

when concatenated are "abcdefghi"



Andy

Can you provide an example please? Sorry, i am a noob.
 
J

James Kanze

Just use >> on strings, and then concatenate them.
Can you explain in more detail please?

std::string word;
while ( input >> word ) {
output << word;
}

will copy the input to the output, removing all spaces. Or

std::string results;
std::string word;
while ( input >> word ) {
results += word;
}

will result in the input, without spaces, in results.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top