加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将一句话里的单词进行倒置,标点符号不倒换(c++)

发布时间:2020-12-13 19:43:07 所属栏目:百科 来源:网络整理
导读:实现一个函数将一句话里的单词进行倒置,标点符号不倒换。比如一句话“i come from wuhan.“倒置后变成"wuhan. from come i"。 #pragma warning (disable:4786) #include iostream #includestack #includestring #include sstream using namespace std; int

实现一个函数将一句话里的单词进行倒置,标点符号不倒换。比如一句话“i come from wuhan.“倒置后变成"wuhan. from come i"。

#pragma warning (disable:4786)
#include <iostream>
#include<stack>
#include<string>
#include <sstream>

using namespace std;

int main(void)
{
stack<string> sstack;
string line,word;

getline(cin,line);

istringstream stream(line);//字符输入流
while(stream >> word)
{
sstack.push(word);
}

while(!sstack.empty())
{
cout << sstack.top() << " ";
sstack.pop();
}

cout << endl;
return 0;
}

问题:VC6.0下getline需要两次才能打印结果,和初衷想法回车即打印不同!应该是VC6.0,在VS和linux应该不会出现这样的问题。解决方法:

(1)建立一个1.CPP

(2)输入#include <string>

(3)右击<string>,选择“打开文档<string>”

(4)用CTRL+F查找 else if (_Tr::eq((_E)_C,_D))

1 else if (_Tr::eq((_E)_C,_D)) 2            {_Chg = true; 3              _I.rdbuf()->snextc(); 4             break; } 
改:

1 else if (_Tr::eq((_E)_C,_D)) 2         {_Chg = true; 3         // _I.rdbuf()->snextc(); 4         // (this comments out the defective instruction) 
5         _I.rdbuf()->sbumpc(); // corrected code 
6         break; } 
保存退出后即可修复这个问题。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读