getline()函数使用有问题吗
#include <iostream>
#include <stdio.h>
#include <string>
#include <cctype>
/**********************************************************
时间:2013-7-27
题目:编写一个程序,从string对象中去掉标点符号。要求输入到程序的字符串必须含有标点符号,
输出结果则是去掉标点符号后的string对象。
Auther:dgh
*********************************************************/
using namespace std;
void MoveString(string &str,int iStrPos);
int main(){
string s;
string::size_type punct_ct = 0; //记录标点符号个数
string::size_type ix=0;
while(getline(cin, s)){ //getline不会忽略开
punct_ct = 0;
for(ix = 0; ix < s.size(); ++ix) {
if( ispunct(s[ix]) ){
MoveString(s,ix);
}
}
cout<<s<<endl;
}
return 0;
}
void MoveString(string &str,int iStrPos){
if(!str.size()
[解决办法]
!iStrPos){
return;
}
else{
for(unsigned int i=iStrPos; i < (str.size()-1) ; ++i){
str[i]=str[i+1];
}
str[str.size()-1]='\0';
}
}
//代码没有优化