By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Are there any long C string across multiple lines

P: n/a
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;
}

Oct 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Oct 19, 3:11 pm, "PengYu...@gmail.com" <PengYu...@gmail.comwrote:
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.


Oct 19 '07 #2

P: n/a
On 2007-10-19 16:11, Pe*******@gmail.com wrote:
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.

--
Erik Wikström
Oct 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.