取一段、找一个、找不着
(本条路线统一用 g++ -std=c++17 -O0 -Wall 编译)
#include <iostream>
#include <string>
int main() {
std::string s = "hello world";
std::string head = s.substr(0, 5);
std::size_t at = s.find("world");
std::size_t none = s.find("xyz");
std::cout << s.size() << "/" << head << "/" << at << "/"
<< (none == std::string::npos) << "\n";
return 0;
}
全部评论