beginer

A

Alf P. Steinbach

how can I write program who removes all ' ' from the string?

There are ways that for an experienced programmer would be easier,
but as a novice, translate to C++:


1) Obtain string s from e.g. program arguments or user, or
simply set it to a well-known test value like "steak brandy cigar".

2) Set string t to empty.

3) For each character position i in s, in ascending order:
{
Let c be character number i in s.
If c is different from a space, then
{
Append c to the end of t.
}
}
 
S

Stuart Golodetz

Darko Lapanje said:
how can I write program who removes all ' ' from the string?

dl

s.erase(std::remove_if(s.begin(), s.end(),
std::bind2nd(std::equal_to<char>(), ' ')), s.end());

HTH,

Stuart.
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top