![]() |
#2
edward90922009-09-11 12:42
|

#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s1;
cout<<"请输入一行带有标点的字符串"<<endl;
getline(cin,s1);
cout<<s1<<endl;
for(string::size_type i=0;i!=s1.size();i++)
{
if(ispunct(s1[i]))
{
for(string::size_type j=i;j<=s1.size();j++)
{
s1[j]=s1[j+1];
}
--i;
}
}
cout<<s1<<endl;
return 0;
}
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s1;
cout<<"请输入一行带有标点的字符串"<<endl;
getline(cin,s1);
cout<<s1<<endl;
for(string::size_type i=0;i!=s1.size();i++)
{
if(ispunct(s1[i]))
{
for(string::size_type j=i;j<=s1.size();j++)
{
s1[j]=s1[j+1];
}
--i;
}
}
cout<<s1<<endl;
return 0;
}
编译时没有问题
但是运行的时候会出错
string subscript out of rang