2013-06-28 32 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"相同。

相關問題