在屏幕上打印符号\作为文本[复制](Print on the screen the symbol \ as text [duplicate])

编程入门 行业动态 更新时间:2024-10-25 16:20:29
在屏幕上打印符号\作为文本[复制](Print on the screen the symbol \ as text [duplicate])

这个问题在这里已有答案:

在字符串中使用\作为文字而不是转义 2答案

我想在运行代码时在我的屏幕上显示以下打印输出:

\begin{tabular} \hline \\

为此,我在我的代码上使用以下命令:

std::cout<<"\begin{tabular}<< std::endl; std::cout<<"\hline \\"<< std::endl;

我得到以下编译器消息(关于第二行代码):

unknown escape sequence: '\h'

以及不完整的打印输出:

egin{tabular} hline\

在第一个中, "\b"缺失,第二个句子中缺少第一个和最后一个\ 。

问题是:有没有人知道如何将\符号作为文本打印出来,这样它就会被打印而不会被解释为命令等?

This question already has an answer here:

using \ in a string as literal instead of an escape 2 answers

I want the following printout to appear in the my screen when I run my code:

\begin{tabular} \hline \\

For that, I am using the following command on my code:

std::cout<<"\begin{tabular}<< std::endl; std::cout<<"\hline \\"<< std::endl;

And I'm getting the following compiler message (regarding the second line of code):

unknown escape sequence: '\h'

and the following incomplete printout:

egin{tabular} hline\

Where in the first one the "\b" is missing and the first and last \ are missing for the second sentence.

The question is: does anyone know how I can print the \ symbol as text, such that it will get printed and not be interpreted as a command, etc?

最满意答案

反斜杠在C ++中形成转义序列。 你有两个选择:

将所有反斜杠加倍,使用"\\hline \\\\" (反斜杠将自行转义,就像在TeX中一样)。 使用C ++ 11原始字符串,看起来像R"(\hline \\)" (文本被引号内的parens包围)。

The backslash forms escape sequences in C++. You have two options:

Double all the backslashes, a la "\\hline \\\\" (the backslash will escape itself, just as in TeX). Use C++11 raw strings, which look like R"(\hline \\)" (the text is enclosed by the parens inside the quotes).

更多推荐

本文发布于:2023-07-28 18:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1307976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   文本   屏幕上   Print   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!