0
1

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 3 years have passed since last update.

string::nposについて

Posted at

string::nposとは

string::nposはstring型のfindで見つからなかったときに返ってくる値です。

お試しコード
int main(){
   string s = "aaa";
   if(s.find('b') == string::npos) cout << "Not found" << endl;
}
結果
Not found

この前int型の変数にstring::nposを入れたら-1だったので、ん?って思ってたので実験してみました。

実験のコード
int main(){
  bitset<100> bit(string::npos);
  if(string::npos==INT64_MAX) cout<<"Yes"<<endl;
  if(string::npos==UINT64_MAX) cout<<"OhYes"<<endl;
  cout<<bit<<endl;
}
結果
OhYes
0000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111

int型の-1は全ビットが1なのでint型に入れたら-1になるよねー。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?