473,789 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4341
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******@gasca d.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.newshostin g.com...

"Karl Heinz Buchegger" <kb******@gasca d.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.newshostin g.com...
"Karl Heinz Buchegger" <kb******@gasca d.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

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

Similar topics

4
3156
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 drama) I've been trying to think of good ways to get Perl code to run inline in a PHP script. Here are a few of my ideas. If anyone has any further ideas, resources, or knows of someone else who's solved this already, please do tell... 1.) The...
6
19468
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 (InStr(Data, "Summary")) Then
7
7116
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 property. This works for IE6 but Opera7.54 and Netscape7.1 add large line spacing between the text blocks and any lines of wrapped text. The line spacing is independant of the font size and is consistent between all lines. ie: it's not larger...
43
13307
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 compiler. I already compiled the program with Intel Compiler (ICL) on Visual C++, and it works fine and fast. I verified that the functions are really inlined. But with GCC 3.4 (Linux+Cygwin) or ICC (Linux), The same program is about 5
3
367
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 there just like macros ? Then why not use macros ?
3
14326
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 choices are to use smaller fonts or choose shorter option strings. inline: I want to put a small graphic immediately to the right of the select.
5
1882
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/ Applications/Great Plains/ Applications/Great Plains/ Applications/Great Plains/ Applications/Great Plains/Servers/
7
16127
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 inline'ed. My question is: If I define a constructor (including its body) or another large member function inside the class, the constructor or the member function is inline or not? why? 2. I learned that if the member function is big we should not...
3
2473
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() -- as seen in the example here How do i solve this ? struct myStr { private: unsigned len;
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10412
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.