VS 2017不会将const char *隐式转换为char * [英] VS 2017 Doesn't Implicitly Convert const char* to char*

查看:93
本文介绍了VS 2017不会将const char *隐式转换为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近安装了VS 2017,遇到了一个奇怪的问题.基本上,如果不将其明确转换为(char *),就无法使用硬编码的字符串.如果我说类似 Function("test")之类的东西,它只会抛出一个错误,指出const char *与char *不兼容.我真的不想坚持VS 2015 :(.任何人都知道如何使VS认识到它们是同一回事吗?

I recently installed VS 2017, and have ran into a weird sort of issue. Basically, I cannot use hard-coded strings without explicitly casting them to (char*). If I said something like Function("test"), it would simply throw an error stating that const char* is incompatible with char*. I really don't want to stick with VS 2015 :(. Anybody know how to make VS recognize that these are the same thing?

非常感谢.

推荐答案

VisualStudio 2017 15.5开始为所有新解决方案设置/permissive-标志,该标志不允许将字符串文字隐式转换为非const char * .您可以在更新代码库以符合C ++标准的同时,编辑解决方案的属性以禁用该标志.在项目属性的"C/C ++"下的语言"选项卡中,它被列为一致性模式".

VisualStudio 2017 15.5 started setting the /permissive- flag for all new solutions, which disallows the implicit conversion of string literals to non-const char*. You can edit the solution's properties to disable that flag while you update your codebase to conform to the C++ standard. It's listed as "Conformance mode" in the "Language" tab under "C/C++" in the project's properties.

这篇关于VS 2017不会将const char *隐式转换为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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