【发布时间】:2020-11-30 01:09:21
【问题描述】:
我写了一个这样的小sn-p:
#include <string>
#include <iostream>
int main() {
std::string s1{"abcdefghijklmnop"};
std::cout << "s1(fg) = " << s1.find_first_of("fg") << '\n';
std::cout << "s1(fo) = " << s1.find_first_of("fo") << '\n';
}
我希望它返回 5 和 string::npos,但它实际上返回
s1(fg) = 5
s1(fo) = 5
为什么会这样?
我的编译标志和 g++ 版本:
$ g++ -std=c++11 main.cpp
$ g++ --version
g++.exe (Rev1, Built by MSYS2 project) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
【问题讨论】: