|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
quick string on multiple lines question
Hi,
A quick question about strings - I just want to declare a string varaible over a few lines for readability sake: string LongSentence = "this is a long sentence that I want to declare over a couple of lines instead of on one long long line."; I get an error "new line in constant" but I thought the compiler would interpret that as being one string. Of course if I define it all on one line it works fine. Does anyone know how to get the compiler to interpret that as one string?? Thanks |
|
#2
|
||||
|
||||
|
Contatenating string literals in C is extremely easy. You just place one literal right after the other without any special characters:
Code:
string LongSentence = "this is a long sentence that I want to"
"declare over a couple of lines instead "
"of on one long long line.";
Another example of this is when you want to create a string literal that contains compiler constants, such as (using Visual C++ v1.52): char g_sVersion[]= { VERSION "," __DATE__ "," __TIME__}; |
|
#3
|
||||
|
||||
|
You could always use the \ character to indicate to the compiler that the string is continued on the next line.
Code:
string LongSentence = "this is a long sentence that I want to \ declare over a couple of lines instead \ of on one long long line."; |
|
#4
|
|||
|
|||
|
thanks!
Thanks guys that was exactly what I was looking for!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > quick string on multiple lines question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|