|
-
string on multiple lines in c
I want to make a long string in C using multiple lines.
I try
Code:
"This is a long ...................\
............... string"
and the a unprintable character is displayed on the output for \
how do I do this without using strcat?
Last edited by xrax; 08-10-2005 at 12:34 PM.
-
The normal way of doing it is taking advantage of the fact that adjacent strings are concatenated by the preprocessor.
"This is a long ..............."
"................... string"
-
Just curious, what happens if you output something like this:
"This is a long ...............\n .............string"
Because that's what I imagine your string looks like, to the compiler. Do you get the same unprintable character?
-
okay I got macros and strings confused.
-
Texan Dragon Moderator
xrax, did you get it figured out?
Remember, if you don't tell C to go to the next line, it'll continue to print on that same line until it can't anymore. The '\n' forces C to go to the next line.
Dragon of the OC Crusaders
Break the rules and you're snack food for this dragon...
-
yes, figured it out. The \ was telling the precompiler to put it on the same line but it was also printing a character in it's place. it should only be used in macros (#define)
-
Great White Shark
hum I am not sure what you meant, but you just wanted that be outputed to the screen. Code should look like this right?
// Messing Around Chp 2
#include <iostream>
using namespace std;
int main()
{
cout << "This is a long................... \n";
cout << "....................... String" << endl;
return 0;
}
Updated 12/27/05
A64 Desktop Rig
DC Opteron [email protected]
1GB UTT@245FSB 2/2/2/7
X1800XT 512MB @PE Speeds
19" Viewsonic WS LCD
2x160GB ATA HDs
NEC 3550 DL-DVD Burner
12.1 Ibook G3
256MB Ram
30GB
-
cout is not available in C and the << operator is a bit shift in C. plus that is 2 strings not one longer string. for macros (pre-processor #define) on multiple lines you add the \ to the end of a line to tell the preprocessor to go to next line. the problem was that the preprocessor was combining the 2 lines but including the \ in the string.
 Originally Posted by "Strogian"
The normal way of doing it is taking advantage of the fact that adjacent strings are concatenated by the preprocessor.
"This is a long ..............."
"................... string"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|