反转句子中的单词 如: I love you 转为 You love I

#include "stdafx.h"
#include "iostream"
#include "vector"
#include "string"
 
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    string str;
    vector<string>vec;
    char a[1]; 
    while (cin >> str)
    {
        a[0]=cin.get();
        if (a[0] == '\n')
        {
            vec.push_back(str);
            break;
        }
        else
        {
            vec.push_back(str);
        }
    }
    for (int i = vec.size(); i>0; i--)
    {
        cout << vec[i - 1] << " ";
    } 

    getchar();
    getchar();
    return 0;
}


你可能感兴趣的:(反转句子中的单词 如: I love you 转为 You love I)