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

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

#pragma warning (disable:4786)
#include
#include
#include
#include

using namespace std;

int main(void)
{
    stack 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

(3)右击,选择“打开文档

(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; } 
复制代码
保存退出后即可修复这个问题。

你可能感兴趣的:(C/C++)