473,416 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

inline text, large strings

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

Jul 22 '05 #1
13 4309
Daniel Heiserer wrote:

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

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2
Daniel Heiserer wrote:
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 ................
";

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.
Jul 22 '05 #3
Karl Heinz Buchegger wrote:
"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.


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

Jul 22 '05 #4
> "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.


Crap! 5 years of programming things like:

printf(" Here\n\
comes \
my \
text");
and now you tell me I can add comments and indentination with "" ""...
Bohooo.. All my pretty source code looks like a piece of #*%& because
I didn't know that.
-Gernot
Jul 22 '05 #5

"Daniel Heiserer" <da*************@bmw.de> wrote in message news:cf*********@usenet.bmw.de...
I get the warning message using g++ (GCC) 3.2.2 on linux:
......warning: multi-line string literals are deprecated

Two string literals immediately abutting are merged into one:

"a" "b" is "ab"

"now a lot of text...\n"
"now a lot of text...\n" ...

does what you want I believe.

Jul 22 '05 #6

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:41***************@gascad.at...
Therefore:

string text= "now a lot of text ................"
"now a lot of text ................"


Note that the new line is just extraneous white space here. If you want
new lines in the string (as his original case did) you must explicitly provide them:

"now a lot of text....\n" "now a lot of text\n"
Jul 22 '05 #7

"Ron Natalie" <ro*@sensor.com> schrieb im Newsbeitrag
news:41**********************@news.newshosting.com ...

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message news:41***************@gascad.at...
Therefore:

string text= "now a lot of text ................"
"now a lot of text ................"


Note that the new line is just extraneous white space here. If you

want new lines in the string (as his original case did) you must explicitly provide them:
"now a lot of text....\n" "now a lot of text\n"


The original text:
char as[]="asasd
asdasd
asdasd";
had _no_ newline characters.
Jul 22 '05 #8
Gernot Frisch wrote:
"Ron Natalie" <ro*@sensor.com> schrieb im Newsbeitrag
news:41**********************@news.newshosting.com ...
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message


news:41***************@gascad.at...
Therefore:

string text= "now a lot of text ................"
"now a lot of text ................"


Note that the new line is just extraneous white space here. If you


want
new lines in the string (as his original case did) you must


explicitly provide them:
"now a lot of text....\n" "now a lot of text\n"

The original text:
char as[]="asasd
asdasd
asdasd";
had _no_ newline characters.


If that were so, wouldn't the first 'asdasd' appear on the same line as
the 'asasd' and the second 'asdasd' on the same line as other parts of
the literal? What are the characters that separate them? Let me put it
this way: what do _you_ call those characters?

V
Jul 22 '05 #9

The original text:
char as[]="asasd
asdasd
asdasd";
had _no_ newline characters.
If that were so, wouldn't the first 'asdasd' appear on the same line

as the 'asasd' and the second 'asdasd' on the same line as other parts of the literal? What are the characters that separate them? Let me put it this way: what do _you_ call those characters?


char a[]="a\
b";
printf(a);

output:
ab

The '\' is only to indicate the compiler, that the next line is
extending this line (as in the #define macros)
-GF

Jul 22 '05 #10
> The '\' is only to indicate the compiler, that the next line is
extending this line (as in the #define macros)


....which the OP didn't use. My fault, sorry for not looking exaclty.
Flame me, I'm unworthy to post here....
Jul 22 '05 #11
"Gernot Frisch" <Me@Privacy.net> wrote:
The original text:
char as[]="asasd
asdasd
asdasd";
had _no_ newline characters.


Since multi-line string constants are not defined in standard C++, it is
somewhat hard to tell what the standard semantics of the above string are.
I guess that there are at least three cases how the above string is
treated by different systems:
- it is an error
- it is a string with newlines
- it is a string without newline
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
Jul 22 '05 #12
On Tue, 17 Aug 2004 15:04:16 +0200, "Gernot Frisch" <Me@Privacy.net>
wrote in comp.lang.c++:
"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.


Crap! 5 years of programming things like:

printf(" Here\n\
comes \
my \
text");
and now you tell me I can add comments and indentination with "" ""...
Bohooo.. All my pretty source code looks like a piece of #*%& because
I didn't know that.
-Gernot


Yes, since the very first 1989 ANSI C standard.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #13

"Dietmar Kuehl" <di***********@yahoo.com> schrieb im Newsbeitrag
news:5b**************************@posting.google.c om...
"Gernot Frisch" <Me@Privacy.net> wrote:
The original text:
char as[]="asasd
asdasd
asdasd";
had _no_ newline characters.
Since multi-line string constants are not defined in standard C++,

it is somewhat hard to tell what the standard semantics of the above string are. I guess that there are at least three cases how the above string is
treated by different systems:
- it is an error
- it is a string with newlines
- it is a string without newline


Re-checked it: VC gives an error, gcc will add a newline.
Jul 22 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the...
6
by: Ratnakar Pedagani | last post by:
Hi, I'm trying to parse the text file, which is of size more than 2mb. I'm using the following sample code Open "c:\sim1.txt" For Input As #1 Do While Not EOF(1) Input #1, Data If...
7
by: Danny | last post by:
I have a small <div> element which contains two text blocks - one within <h5> tags and the other within <p> tags. I don't want any extra line spacing between elements so use the display:inline...
43
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the...
3
by: junky_fellow | last post by:
What is an inline function ? When should we declare a particular function as inline ? If a function is declared to be inline, does that mean that the entire code for that function is subtituted...
3
by: i_dvlp | last post by:
I'm trying to replicate a fancy drop-down control (MS-egads!) with form <select><option> It doesn't look like you can specity width as an attribute or define width with CSS. It looks like my...
5
by: soup_nazi | last post by:
I want to remove duplicate entries within a text file. So if I had this within a text file... Applications/Diabetic Registry/ Applications/Diabetic Registry/ Applications/Diabetic Registry/...
7
by: Wu Shaohua | last post by:
Hi Guys, 1. As we know usually we should not define a constructor as inline. I also learned if we define a member function inside the class this member function will be automatically be...
3
by: news.inode.at | last post by:
Sorry for this stupid question, but i am lost. If i write an stringlib with += overload operators (no i do not, but my thing is much more complicated) , and i have to precalculate the strlen() --...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.