substr函数用不了
#include<bits/stdc++.h>
using namespace std;
string n,a,s;
int m,x,y,k,b;
char w;
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>x;
if(x==1)
{
cin>>y>>w;
for(int j=1;j<=y;j++) n+=w;
}
if(x==2)
{
cin>>a;
n=n+a;
}
if(x==3)
{
cin>>k>>b;
n.substr(k,b);
}
}
cout<<n;
return 0;
}
没有取子串
substr要有返回值啊。
// string::substr
#include <iostream>
#include <string>
int main ()
{
std::string str="We think in generalities, but we live in details.";
// (quoting Alfred N. Whitehead)
std::string str2 = str.substr (3,5); // "think"
std::size_t pos = str.find("live"); // position of "live" in str
std::string str3 = str.substr (pos); // get from "live" to the end
std::cout << str2 << ' ' << str3 << '\n';
return 0;
}
怎么不能用?你想达到什么结果?