【发布时间】:2016-09-25 09:51:17
【问题描述】:
我有以下代码:-
string name = "hello world";
size_t find = name.find("world");
if (find != string::npos) {
cout<<"match found at "<<find;
}
else{
cout<<find;
}
此程序运行良好,并按预期打印 6 个输出。
但是如果我把它改成size_t find = name.find('\n');
它将垃圾值打印为18446744073709551615。 find 函数在找不到匹配的字符串时是否打印垃圾值??
【问题讨论】:
-
值不是“垃圾”——它是
string::npos。
标签: c++ string function output