使用strrev在C ++中正确反转字符串

时间:2016-04-18 14:06:20

标签: c++ arrays output

我希望用户输入strrev的字符串来反转但是当用户输入字符串空格时由于某种原因是不允许的,所以如果有人输入你好我的名字是stan。输出只是nats,我怎样才能获得接受空格的功能?

#include<iostream>
#include <cstring>
#include<string.h>
using namespace std;
int main()
{
    char str[] = "This is a c-StyleString";
    //cout <<"Enter the string:" << endl;
    //cin >> str;
    cout << "Reverse of the given string is: " << strrev(str);
    return 0;
}

1 个答案:

答案 0 :(得分:5)

strrev是一个已弃用的函数,仅在Microsoft工具链中可用,不应使用。您可以使用std::reverse反向字符串。

相关问题