C ++中几行的相同命令

时间:2013-06-28 09:02:54

标签: c++ c windows winapi

我想在C ++中用几行代写一个变量。更准确地说是在WINAPI中。

类似于:(如果\是执行它的命令,)

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.";

问题在于我得到了“|||”无论我在我的代码中使用过\。我不希望它出现。 我该怎么办?

1 个答案:

答案 0 :(得分:6)

有几种选择。这是两个:

  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 ++允许您逐个编写多个字符串文字,并在编译时自动连接它们。也就是说,"a" "b""ab"相同,就C ++而言。