使用strrev在C ++中正确反转字符串 [英] Properly reversing a string in C++ using strrev

查看:73
本文介绍了使用strrev在C ++中正确反转字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户输入用于strrev的字符串,但是由于某种原因,当用户输入字符串时,不允许输入空格,因此,如果有人输入hello,我的名字就是stan.输出仅是nat,如何获取接受空白的函数?

I would like the user to enter the string for strrev to reverse however when the user enters the string spaces are not allowed for some reason so if someone enters hello my name is stan. the output is only nats, How can i get the function to accept white space?

#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;
}

推荐答案

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

strrev is a deprecated function, which was only available in Microsoft toolchain and should not be used. You can reverse string with std::reverse.

这篇关于使用strrev在C ++中正确反转字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆