Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 8th, 2003, 02:05 PM
Authorized User
 
Join Date: Sep 2003
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
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
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
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
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
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





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





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