内联文本,大字符串 [英] inline text, large strings
问题描述
我想填写这样的字符串:
使用命名空间std;
string text =" ;
现在很多文字................
现在很多文字....... .........
现在很多文字................
现在很多文字................
现在很多文字................
" ;;
我在linux上使用g ++(GCC)3.2.2收到警告信息:
.......警告:不推荐使用多行字符串文字
有没有办法将大部分文本写入
代码而不会收到这些警告?
我不想写这样的东西:
字符串文字;
text + ="现在很多文字.. .............." ;;
text + ="现在很多文字................ " ;;
text + ="现在很多文字................" ;;
text + =" ;现在很多文字................" ;;
text + ="现在很多文字................" ;;
- 谢谢,daniel
Hi,
I want to fill a string like this:
using namespace std;
string text="
now a lot of text ................
now a lot of text ................
now a lot of text ................
now a lot of text ................
now a lot of text ................
";
I get the warning message using g++ (GCC) 3.2.2 on linux:
.......warning: multi-line string literals are deprecated
Is there a way to write large portions of text right into the
code without getting these warnings?
I do not want to write something like this:
string text;
text+="now a lot of text ................";
text+="now a lot of text ................";
text+="now a lot of text ................";
text+="now a lot of text ................";
text+="now a lot of text ................";
-- thanks, daniel
推荐答案
Daniel Heiserer写道:
Daniel Heiserer wrote:
我想填写像这样的字符串:
使用命名空间std;
字符串文本="
现在很多文字................
现在很多文字................
现在很多文字................
现在很多文字................
现在很多文字................
" ;;
我在linux上使用g ++(GCC)3.2.2收到警告信息:
......警告:不推荐使用多行字符串文字
有没有办法在没有得到这些警告的情况下将大部分文本写入
代码?
我不想写这样的东西:
字符串文字;
文字+ =&现在很多文字................" ;;
文字+ =现在很多文字.. ..............." ;;
text + =" ;现在很多文字................" ;;
文字+ =现在很多文字............ ...." ;;
text + ="现在很多文字................" ;;
Hi,
I want to fill a string like this:
using namespace std;
string text="
now a lot of text ................
now a lot of text ................
now a lot of text ................
now a lot of text ................
now a lot of text ................
";
I get the warning message using g++ (GCC) 3.2.2 on linux:
......warning: multi-line string literals are deprecated
Is there a way to write large portions of text right into the
code without getting these warnings?
I do not want to write something like this:
string text;
text+="now a lot of text ................";
text+="now a lot of text ................";
text+="now a lot of text ................";
text+="now a lot of text ................";
text+="now a lot of text ................";
>
" now" a 很多 的 text
相当于现在很多文本。
换句话说:编译器会破坏个别字符串
将文字单独写入一个文字。
因此:
string text ="现在很多文字.. ..............."
"现在很多文字................"
"现在很多文字................"
"现在很多文字...... ...............
现在很多文字................"
;
完全符合您的要求。
-
Karl Heinz Buchegger
kb******@gascad.at
>
Daniel Heiserer写道:
Daniel Heiserer wrote:
我想填写这样的字符串:
using namespace std;
string text ="
现在很多文字................现在很多文字.......... ..... 。
现在很多文字................
&;;;
Hi,
I want to fill a string like this:
using namespace std;
string text="
now a lot of text ................
now a lot of text ................
now a lot of text ................
";
我会推荐:
使用命名空间std;
string text =
"现在很多文字....... ........."
"现在很多文字................"
"现在很多文字................"
"现在很多文字........ ........"
"现在很多文字................"
;
编译器将其视为单个字符串(避免文本+ =""
操作),如果你有一个像样的文本编辑器
添加引号*在你输入(或剪切并粘贴)你的文字到
来源之后会很简单。
I''d recommend:
using namespace std;
string text=
"now a lot of text ................"
"now a lot of text ................"
"now a lot of text ................"
"now a lot of text ................"
"now a lot of text ................"
;
The compiler treats this as a single string (avoiding the text+=""
operation), and if you have a decent text editor it will be simple to
add the quotes *after* you''ve typed (or cut&pasted) your text into the
source.
Karl Heinz Buchegger写道:
Karl Heinz Buchegger wrote:
" now" a 很多 的 text
相当于现在很多文本。
换句话说:编译器会将各个字符串
文字单独放入一个文字中。
因此:
string text ="现在很多文字................"
现在很多文字................"
现在很多文字.............. ..
现在很多文字................"
现在很多文字...... ..........
;
完全符合您的要求。
"now " "a " "lot " "of " "text"
is equivalent to "now a lot of text".
In other words: The compiler will catanate individual string
literals into one literal on its own.
Therefore:
string text= "now a lot of text ................"
"now a lot of text ................"
"now a lot of text ................"
"now a lot of text ................"
"now a lot of text ................"
;
does exactly what you want.
除非OP想要换行符,他必须在这种情况下手动添加
:
string text ="现在很多文字.. ............... \ n"
现在很多文字................ \\现在很多文字................ \ n"
"现在很多文字.. .............. \ n"
"现在很多文字................" ;
;
Unless the OP wants the newlines to be present, which he would have to
add manually in this case:
string text= "now a lot of text ................\n"
"now a lot of text ................\n"
"now a lot of text ................\n"
"now a lot of text ................\n"
"now a lot of text ................"
;
这篇关于内联文本,大字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!