C++ 字符串查找:寻找指定字符
C++ 代码
#include <iostream>
#include <string>
using namespace std;
int main() {
char target;
string str;
cin >> target;
cin.ignore(); // 忽略换行符
getline(cin, str);
int index = str.find_last_of(target);
if (index != string::npos) {
cout << "index = " << index << endl;
} else {
cout << "Not Found" << endl;
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/mGGH 著作权归作者所有。请勿转载和采集!