如何使用{“data":“0001"}'的输入声明char * [英] how to declare char * with input of {"data": "0001"}'
本文介绍了如何使用{“data":“0001"}'的输入声明char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的输入数据具有这种格式 { "data": "0001" }'.当我如下声明时,在 VC 中,它显示未找到用户定义的文字运算符"的味精.如何用这种格式声明和初始化?
my input data have this format { "data": "0001" }'. when I declare as follows, in VC, it showed msg of "user-defined literal operator not found". how to declare and initialize with this format?
const char * u = "{ "data": "0001" }'";
推荐答案
从 C++11 开始,您可以选择使用 原始字符串文字.
From C++11 onwards, you have the option of using raw string literals.
有了它,您将能够做到这一点:
With that you will be able to do this:
const char * u = R"({ "data": "0001" }')";
如果你不能使用 C++11 的特性,那么就使用老式的方法来转义双引号:
If you cannot use C++11 features, then go for the old-fashioned way of escaping the double quotes like this:
const char * u = "{ \"data\": \"0001\" }'";
这篇关于如何使用{“data":“0001"}'的输入声明char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文