#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
string a;
int m, n;
cout << "please input the string: ";
cin >> a;
cout << "please input m and n : ";
cin >> m >> n;
a.erase(a.begin()+m, a.begin()+m+n);
//a.erase(m, n);
cout << "after erasing the string is:" << endl;
cout << a;
return 0;
}
这个是C++的代码,当然,用不用迭代器都可以。
#include <stdio.h>
int main()
{
char a[100];
int i = 0;
int m, n;
printf("please input the string: ");
while((a[i++] = getc(stdin)) != '\n');
a[i] = '\0';
printf("please input m and n: ");
scanf("%d%d", &m, &n);
for(i = m; i != 100; i++)
{
a[i] = a[i+n];
if(a[i] == '\0')
break;
}
printf("after erasing the string is: ");
printf("%s", a);
return 0;
}