C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 30th, 2003, 06:53 PM
theRaginCajun theRaginCajun is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: USA
Posts: 144 theRaginCajun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old June 30th, 2003, 07:05 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,836 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 7 h 41 sec
Reputation Power: 446
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__};

Reply With Quote
  #3  
Old June 30th, 2003, 08:15 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,508 Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 16 m 59 sec
Reputation Power: 865
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."; 

Reply With Quote
  #4  
Old June 30th, 2003, 11:38 PM
theRaginCajun theRaginCajun is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: USA
Posts: 144 theRaginCajun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
thanks!

Thanks guys that was exactly what I was looking for!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > quick string on multiple lines question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway