Cout c ++有很多行

时间:2014-04-04 22:52:47

标签: c++ cout

我想用cout在c ++中打印一条大邮件。

示例:

cout<<"Camera could not be opened in the requested access mode, because another
              application (possibly on another host) is using the camera."<<endl;

但是我收到了错误。

任何帮助?

2 个答案:

答案 0 :(得分:6)

这样的事情:

 cout<<"Camera could not be opened in the requested access mode, because another "
          "application (possibly on another host) is using the camera."<<endl;

 cout<<"Camera could not be opened in the requested access mode, because another\n"
          "application (possibly on another host) is using the camera."<<endl;

在C和C ++中,编译器将连接两个彼此相邻的字符串。

答案 1 :(得分:2)

您无法直接在多行中拆分普通字符串文字。我认为你可以使用连接字符将它们分开。但是,这也不会嵌入换行符。要获得这些,您需要使用\n。我认为你可以使用原始字符串:

char const* strcont = "foo\
bar";
char const* strcat = "foo"
                     "bar";
char const* strraw = R"(foo
bar)";

前两个字符串是相同的:相邻的字符串是连接的。第三个也包含换行符。