Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Remove space from input (http://www.velocityreviews.com/forums/t958728-remove-space-from-input.html)

eli m 03-16-2013 06:53 PM

Remove space from input
 
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 03-16-2013 07:10 PM

Re: Remove space from input
 
On Saturday, 16 March 2013 20:53:59 UTC+2, eli m wrote:
> 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.


James Kanze 03-16-2013 10:23 PM

Re: Remove space from input
 
On Saturday, March 16, 2013 6:53:59 PM UTC, eli m wrote:
> 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.

--
James

eli m 03-17-2013 06:12 PM

Re: Remove space from input
 
Just use >> on strings, and then concatenate them.
>
>
>
> --
>
> James

Can you explain in more detail please?


eli m 03-18-2013 12:29 AM

Re: Remove space from input
 
On Sunday, March 17, 2013 1:06:48 PM UTC-7, Andy Champ wrote:
> On 17/03/2013 18:12, eli m wrote:
>
> > Just use >> on strings, and then concatenate them.

>
> >>

>
> >>

>
> >>

>
> >> --

>
> >>

>
> >> James

>
> > Can you explain in more detail please?

>
> >

>
> 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.

James Kanze 03-18-2013 05:30 PM

Re: Remove space from input
 
On Sunday, 17 March 2013 18:12:57 UTC, eli m wrote:
> 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.

--
James



All times are GMT. The time now is 09:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.