On 12/10/2012 7:11 PM, Mike Copeland wrote:
> How do I remove the last character of a basic::string? Specifically,
> I'm using fgets to read lines from a text file, and each ends with the
> characters '\10' and '\0'. When I assign the c-string variable to a
> basic::string the '\0' is dropped, but the '\10' remains. I want to
> erase this character before subsequent processing, but I can't find any
> way to do so. I've tried:
>
> string::iterator itr = str.end()-1;
> if(*itr == '\10')
> str.erase(*itr, 1);
What do you think that does? RTFM on 'std::string::erase' member functions.
Have you tried debugging your program to see whether your 'str.erase' is
in fact being called when you need it? And if it does get called, what
is the actual effect? Is '\10' in fact the right character to be
looking for?
> but that doesn't work. Trying to use rbegin() doesn't compile. 8<{{
> Please advise. TIA
Your program has at least one bug. Debug your program.
V
--
I do not respond to top-posted replies, please don't ask
|