getline读入一整行字符串就会错误
查看原帖
getline读入一整行字符串就会错误
945669
wsh1c6楼主2024/3/16 22:58
#include<iostream>
using namespace std;
string s,str;
int op,a,b,q;
int main()
{
	cin>>q>>s;
	while(q--)
	{
		cin>>op;
		if(op==1)
		{
			cin>>str;
			s+=str;
			cout<<s<<endl;
		}
		else if(op==2)
		{
			cin>>a>>b;
			s=s.substr(a,b);
			cout<<s<<endl;
		}
		else if(op==3)
		{
			cin>>a>>str; 
			s.insert(a,str);
			cout<<s<<endl;
		}
		else
		{
			cin>>str;
			if(s.find(str)!=-1)
			cout<<s.find(str)<<endl;
			else cout<<"-1"<<endl;
		} 
	}
	return 0;
}

这段代码换成getline读入字符串就会出现错误

2024/3/16 22:58
加载中...