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: Thomas Maeder
Subject: Re: find_last_not_of not returning string::npos
Date: Sat, 28 Mar 2009 09:11:08 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)

Toby <tjdonaldson@gmail.com> writes:

> It seems that string's find_last_not_of method 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?

Neither.

std::string::npos is of type std::string::size_type (which is an
unsigned type). Assigning this value to a signed type that isn't
sufficiently wide to hold it is asking for trouble.

What do you get from

void test()
{
  string s = "  ";
  cout << "s.find_last_not_of(' ') = " << s.find_last_not_of(' ') << endl
       << "string::npos = " << string::npos << endl;
}

?


reply via email to

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