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

Bee*_*eee 0 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;
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*eyA 5

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

  • @Beeeee,我(严肃地说,不开玩笑!)建议你在为时已晚之前改变学校. (5认同)