0

我想在 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.";

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

4

1 回答 1

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

于 2013-06-28T09:05:20.567 回答