help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find_last_not_of not returning string::npos


From: Toby
Subject: Re: find_last_not_of not returning string::npos
Date: Thu, 26 Mar 2009 18:24:45 -0700 (PDT)
User-agent: G2/1.0

On Mar 26, 5:43 pm, Toby <tjdonald...@gmail.com> wrote:
> It seems that string'sfind_last_not_ofmethod isn't returning
> string::npos:
>
> void test() {
>   string s = "  ";
>   int i = s.find_last_not_of(' ');
>   cout << "i = " << i << endl                       // prints -1
>        << "string::npos = " << string::npos
>        << endl;
>
> }
>
> On g++ (Ubuntu 4.3.2-1ubuntu12) 4.3. I get this output:
>
>   i = -1
>   string::npos = 4294967295
>
> Is this a bug? Or am I mis-reading the documentation?

I found the problem: the variable i should be of type size_t, not int:

  size_t i = s.find_last_not_of(' ');  // returns string:npos as
expected

Toby


reply via email to

[Prev in Thread] Current Thread [Next in Thread]