首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

getline()函数使用有有关问题吗

2013-08-13 
getline()函数使用有问题吗getline[解决办法]#include iostream#include stdio.h#include string#in

getline()函数使用有问题吗

                                                  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';
}
}

//代码没有优化

热点排行