[Tuxcpprogramming] Removing white space from beginning of a string

Mark Phillips mark at austrics.com.au
Tue Jul 10 12:06:49 UTC 2001


I want a means of removing whitespace from
the beginning of a string (from the STL
string package).  The following code does
this:

unsigned int i;
for (i=0; i<line.length(); i++)
  if (!(line[i]==' ' || line[i]=='\t'))
    break;
line.erase(0,i);

However I was wondering whether there
is a better way.  I would have thought this
is a very common operation and expected
to find something in the <string> library
which would do this for me, but I can't
find anything.  Have I missed something?
Or is the above code the best solution?

Thanks,

Mark.





More information about the tuxCPProgramming mailing list