C++ 代码

#include <iostream>
#include <string>
using namespace std;

int main() {
    char targetChar;
    string str;

    cin >> targetChar;
    cin.ignore(); // 忽略换行符
    getline(cin, str);

    int index = str.rfind(targetChar);
    if (index != string::npos) {
        cout << "index = " << index << endl;
    } else {
        cout << "Not Found" << endl;
    }

    return 0;
}
C++ 字符串查找:指定字符位置

原文地址: https://www.cveoy.top/t/topic/mGGK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录