<分区>
下面的语句是什么意思?
string s="Joe Alan Smith"";
cout << (s.find("Allen") == string::npos) << endl;
标签 c++
<分区>
下面的语句是什么意思?
string s="Joe Alan Smith"";
cout << (s.find("Allen") == string::npos) << endl;
最佳答案
实际上string::find()
返回找到的字符串的位置,但是如果没有找到给定的字符串,则返回string::npos
,其中 npos
表示没有位置。
npos
是一个无符号整数值,标准定义为-1
(有符号表示)表示没有位置。
//npos is unsigned, that is why cast is needed to make it signed!
cout << (signed int) string::npos <<endl;
输出:
-1
参见 Ideone:http://www.ideone.com/VRHUj
关于c++ - string::npos 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5096243/