如何在字符串文字中使用双引号? [英] How can I get double quotes into a string literal?

查看:127
本文介绍了如何在字符串文字中使用双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 printf()语句创建了以下输出:

I have the following output created using a printf() statement:

printf("She said time flies like an arrow, but fruit flies like a banana.");

但是我想将实际报价放在双引号中,所以输出是

but I want to put the actual quotation in double-quotes, so the output is


她说时间像箭一样飞,但是水果像香蕉一样飞。

She said "time flies like an arrow, but fruit flies like a banana".

不会干扰 printf()语句中用于包装字符串文字的双引号。

without interfering with the double quotes used to wrap the string literal in the printf() statement.

我该怎么做?

推荐答案

用反斜杠转义引号:

printf("She said \"time flies like an arrow, but fruit flies like a banana\"."); 

有特殊的转义字符,并用前导反斜杠表示。

There are special escape characters that you can use in string literals, and these are denoted with a leading backslash.

这篇关于如何在字符串文字中使用双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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