24
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

std::string::nposの正体

Posted at

string::findで値が見つからなかった場合に返す値として定義されています。

Referenceより

static const size_type npos = -1;
This is a special value equal to the maximum value representable by the type size_type. The exact meaning depends on context, but it is generally used either as end of string indicator by the functions that expect a string index or as the error indicator by the functions that return a string index.

雑に訳せば「size_typeのとりうる最大値」となります。size_typeunsigned intで示されており、補数表現の最大値と-1が等価になるため、-1とされているのだと思います。

24
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?