This tip actually comes out of a "bug" that Blommis found a while back. If you want to create a string (or you can do this for comments too) that sits on more than one line, you can use a backslash at the end of the line to extend it to the next. For example:
#include <stdio.h>
// My Comment \
ends here
int main() {
printf("I\
like\
to\
code\
weird");
return 0;
}
Now that you have this knowledge, I don't really recommend you ever use it (especially for comments, since you can use /* */ for comments). But for really long strings, it might be useful.
For slightly more information on this, see here:
http://forums.sdltutorials.com/viewtopic.php?f=18&t=67
-----------------------------
(main.h)
#include "english.lng"
#include "polish.lng"
(english.lng)
#ifdef LANG_ENGLISH
#define _text << "Some text\n"\
<< "in two lines\n";
#endif
(use in main.cpp)
cout _text;
----------------------------
On the start of main.cpp I was writing #define LANG_ENGLISH or #define LANG_POLISH for selecting language (program was compiling with only one language, but it was OK for very small program).
Email (required, not published):
Website:
#define DO_IT(x, y) \
{ \
x = y; \
printf("I done did it!\n"); \
}
What you're essentially doing is using the escape character '\' to escape the newline character. Using it to extend comments is just asking for trouble.
As for long strings, C and C++ both automatically concatenate adjacent string literals. You don't really need to use the escape here:
const char* mytext = "This text "
"is not really"
"long enough"
"to merit this.\n";
Email (required, not published):
Website:
Email (required, not published):
Website: