'\\\<br/>'或“\\\<br/>”之间的区别是什么?在C ++? [英] What is the difference between &#39;\n&#39; or &quot;\n&quot; in C++?

查看:201
本文介绍了'\\\<br/>'或“\\\<br/>”之间的区别是什么?在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个新行 \\\
在一些代码示例中使用了2种不同的方式。第一个是'\\\
'
,第二个是\\\
。有什么区别,为什么你会使用'\\\
'

I've seen the new line \n used 2 different ways in a few code examples I've been looking at. The first one being '\n' and the second being "\n". What is the difference and why would you use the '\n'?

$ c>'\\\
'表示一个字符,\\\
表示一个字符串,但是这么做吗?

I understand the '\n' represents a char and "\n" represents a string but does this matter?

推荐答案

'\\\
'
是一个字符常数。

\\\
是等同于 {'\\\
','\ 0'}
\\\
加上空终止符)

"\n" is a pointer to character array equivalent to {'\n', '\0'} (\n plus the null terminator)

EDIT

我意识到我解释了这个差异,但没有回答这个问题。

I realize i explained the difference, but didn't answer the question.

您使用哪一个取决于上下文。如果你正在调用一个需要一个字符的函数,并且\\\
,则使用'\\\
'

Which one you use depends on the context. You use '\n' if you are calling a function that expects a character, and "\n", if it expects a string.

这篇关于'\\\<br/>'或“\\\<br/>”之间的区别是什么?在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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