2013-06-28 33 views
0

我想在C++的几行中编写单个变量。更确切地说在WINAPI中。在C++中使用多行的相同命令

喜欢的东西:(如果\是做它的命令,)

str=" This is a sample file trying to write multiple lines. \n but it is not same as line break. \ 
I am defining the same string over several lines. This is different from using backslash n. \ 
This is not supposed to print multipline in screen or in write file or on windows display. This\ 
is for ease of programming."; 

这样做的问题是,我得到了“|||”无论我在代码中使用\。我不想让它出现。 我该怎么办?

+0

是的!我无法删除它。但你们可以关闭它。请这样做! – user2178841

回答

5

有几种选择。这里有两个:

  1. 把字符串的内容放到一个文件中,并将文件内容读入到字符串中。当你发现自己使用很多长字符串时,这可能是“正确”的方式。

  2. 使用以下语法:

    str = "This is a string that is going over several lines " 
         "but it does not include line breaks and if you print " 
         "the string you will see that it looks like it was " 
         "written normally."; 
    

    - C++允许你写接连几个字符串和在编译时会自动连接它们。就C++而言,"a" "b""ab"相同。

相关问题