#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string str = "这是一段中文1234,其中123是需要保留的数字。";
size_t pos = str.find_first_of("0123456789"); // 找到第一个数字的位置
if (pos != string::npos) {
cout << "第一个数字出现的位置为:" << pos << endl; // 输出结果:第一个数字出现的位置为:9
}
return 0;
}
C++实现找到字符串第一个数字的位置
于 2023-10-07 17:51:09 首次发布