问问这个怎么做啊?刚开始学,不会😭

img


#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cout<<"请输入一个字符串:"<<endl;
    getline(cin,s);
    char c;
    cout<<"请输入要查找的字母:";
    cin>>c;
    int i;
    for(i=0;i<s.length();i++){
        if(s[i] == c){
            cout<<"字母"<<c<<"在字符串"<<s<<"中第一次出现在第"<<i+1<<"个"<<endl;
            break;
        }
    }
    if(i==s.length()){
        cout<<"在字符串"<<s<<"中没有字母"<<c<<endl;
    }
}

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
int main()
{
    string s;
    char c;
    cout << "请输入一个字符串:";
    getline(cin, s);
    cout << "请输入要查找的字母:";
    cin >> c;
    string str = s;
    transform(str.begin(), str.end(), str.begin(), ::tolower);
    char temp = c;
    if(c <= 'Z'){
        temp = c + 32;
    }
    for(int i = 0;i < s.length();i++){
        if(s.at(i) == temp){
            cout << "字母" << c << "在字符串" << s << "第一次出现在第" << i + 1 << "个" << endl;
            return 0;
        }
    }
    cout << "在字符串" << s << "中没有字母" << c << endl;
    return 0;
}