字符串文字C ++? [英] String literals C++?

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

问题描述

我需要在C ++中编写以下C#代码(如果可能)。

I need to do the following C# code in C++ (if possible). I have to const a long string with lots of freaking quotes and other stuff in it.

const String _literal = @"I can use "quotes" inside here";


推荐答案

当前标准)。

这是C ++ 0x草案标准的一部分,但是目前还不可用。

That is part of the C++0x draft standard but that's not readily available just yet.

现在,您只需要明确引用它:

For now, you just have to quote it explicitly:

const std::string _literal = "I have to escape my quotes in \"C++03\"";

一旦C ++ 0x成为现实,您就可以写:

Once C++0x becomes reality, you'll be able to write:

const std::string _literal = R"(but "C++0x" has raw string literals)";

,当您需要字面值:

const std::string _literal = R"DELIM(more "(raw string)" fun)DELIM";

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

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