这个问题在这里已有答案:
在字符串中使用\作为文字而不是转义 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 answersI 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).更多推荐
发布评论