Are there any long C string across multiple lines

P

PengYu.UT

Hi,

In python, triple quote (""") can be used to quote a paragraph
(multiple lines). I'm wondering if there is any equivalent in C++.

For the following code, I could write the long string in a single line
with "\n" in the middle, or I could use multiple cout and endl. But I
just feel more readable if I can have the whole paragraph as a string.

Thanks,
Peng

#include <iostream>

int main() {
std::cout << "a long long long long long
long long long long long long string" << std::endl;
}
 
T

tragomaskhalos

Hi,

For the following code, I could write the long string in a single line
with "\n" in the middle, or I could use multiple cout and endl. But I
just feel more readable if I can have the whole paragraph as a string.

Thanks,
Peng

#include <iostream>

int main() {
std::cout << "a long long long long long
long long long long long long string" << std::endl;

For a single ubbroken line:
std::cout << "a long long long long long"
" long long long long long long string" << std::endl;


For a split line (which is what you're asking for):
std::cout << "a long long long long long\n"
" long long long long long long string" << std::endl;

iow you can put multiple string literals together and
the compiler will concatenate them.
Not quite as elegant as you want but hey-ho.
 
G

Guest

Hi,

In python, triple quote (""") can be used to quote a paragraph
(multiple lines). I'm wondering if there is any equivalent in C++.

For the following code, I could write the long string in a single line
with "\n" in the middle, or I could use multiple cout and endl. But I
just feel more readable if I can have the whole paragraph as a string.

Thanks,
Peng

#include <iostream>

int main() {
std::cout << "a long long long long long
long long long long long long string" << std::endl;
}


Two string literals in a row are concatenated into one string literal:

int main()
{
std::cout << "bla bla bla bla bla bla bla bla bla bla bla bla bla bla"
" bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla"
" bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla";
}

For explicit linebreaks you still need to use \n.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top