请教一个简单的代码
如果该字符串其中有子串“STUDENT”,则将其替换为“YOUNG”,并显示出来.
这个代码怎么写 ,感谢
如果该字符串其中有子串“STUDENT”,则将其替换为“YOUNG”,并显示出来.
这个代码怎么写 ,感谢
#include<iostream>
#include<string>
using namespace std;
void main()
{
string a;
cin>>a;
if(a.find("STUDENT",0)!=-1)
{
a.replace(a.find("STUDENT"),7,"YOUNG");
cout<<a<<endl;
}
else cout<<"没有该子串";
}