Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 8th, 2003, 02:05 PM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Continuing a line of code in C++

I have a long line of code:

cout << "Your gas mileage for this trip is: " << setprecision(5) << milesPerGallon << " MPG " << endl;

How do I continue this string literal to the next line without breaking the code? I know in VB you use & _ but how do you continue a line in C++?

Thanks in advance...Kevin

Reply With Quote
  #2 (permalink)  
Old December 16th, 2003, 10:29 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
cout<<"Your "
    <<"gas "
    <<"mileage "
    <<"may "
    <<"vary."
    <<endl;
Reply With Quote
  #3 (permalink)  
Old January 8th, 2004, 06:41 AM
Authorized User
 
Join Date: Dec 2003
Location: Bristol, , United Kingdom.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alternatively finish each line with a backslash slash:

printf("this is a very long linewhich continues hereand here it finally ends");

Georges
Reply With Quote
  #4 (permalink)  
Old January 25th, 2004, 05:09 AM
Authorized User
 
Join Date: Dec 2003
Location: Bristol, , United Kingdom.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Something went wrong with that post which should have read:

printf("This is a very long line ending and going straight on to this one and then to the last bit");

Georges
Reply With Quote
  #5 (permalink)  
Old January 25th, 2004, 05:11 AM
Authorized User
 
Join Date: Dec 2003
Location: Bristol, , United Kingdom.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem with back slashes - we trya again:

printf("part one of long line \part 2 of long line \part 3 of long line ");


Georges
Reply With Quote
  #6 (permalink)  
Old January 25th, 2004, 05:14 AM
Authorized User
 
Join Date: Dec 2003
Location: Bristol, , United Kingdom.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Seems impossible to write this - it looks ok in 'preview'
but fails on display! So: I'll substitute '@' for a backslash \\.

printf("part one of a lomg line @
part 2 of a long line @
last past of a long line");


Georges
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to understand this line of code chriscym XSLT 2 April 17th, 2007 10:48 PM
Continuing Deployment Questions plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 March 6th, 2007 05:18 PM
Continuing DEADLOCK Problem Ron Howerton SQL Server ASP 1 September 21st, 2005 02:55 PM
new line html code crmpicco HTML Code Clinic 1 June 14th, 2005 08:25 AM
Reading one character and then continuing? jacob J2EE 4 February 15th, 2004 05:40 PM



All times are GMT -4. The time now is 06:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.