首頁 C++【C++】判斷是否存在於字串中237 點閱數 培哥2024年4月28日 如果找到,find() 會回傳起始索引,否則回傳 string::npos (no position)。#include <iostream> #include <string> using namespace std; int main(){ string s = "hello world"; cout << (s.find("o") != string::npos); }