为啥cin换成getline全错,原本是对的
查看原帖
为啥cin换成getline全错,原本是对的
1449927
cccckick楼主2024/10/22 20:59
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cin.ignore();
getline(cin,str);
for(int i=0;i<n;i++)
{
	int x;
	cin>>x;
	if(x==1)
	{
		string temp;
		cin>>temp;
		str+=temp;
		cout<<str;
		cout<<endl;
	} 
	else if(x==2)
	{
		int x1,y1;
		cin>>x1>>y1;
		str=str.substr(x1,y1);
		cout<<str;
		cout<<endl;
	}
	else if(x==3)
	{
		int x1;
		cin>>x1;
		string temp;
		cin>>temp;
	str=str.insert(x1,temp);
		cout<<str;
		cout<<endl;
		
		
	}
	else {
    string temp;
    cin >> temp;

    size_t pos = str.find(temp);  
    if (pos != string::npos) {
        cout << pos << endl;  
    } else {
        cout << -1 << endl;  
    }
}
		
	}
	
	
	
}
2024/10/22 20:59
加载中...