Concatnating strings that are too long for one line

This is a discussion on Concatnating strings that are too long for one line within the C++ Programming forums, part of the General Programming Boards category; Hi, this is a really simple question but I can't figure it out. If I want to pass a really ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    10

    Concatnating strings that are too long for one line

    Hi, this is a really simple question but I can't figure it out. If I want to pass a really long string to a function, it is really inconvenient to keep it all on one line since then I need to scroll horizontally to see it all.

    I first tried using the + operator like:
    Code:
    function ("Long " +
        "String");
    However apparently I can't do that.

    I also tried:
    Code:
    function ("Long \
        String");
    But for some reason the backslash seems to introduce extra characters into the string and causes my function to fail.

    I'm sure there has got to be a way to do this.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    Let the compiler do the concatenation for you:
    Code:
    function("Long "
             "String");
    This relies on the fact that adjacent string literals are combined into a single string literal, and that whitespace is not significant in this context.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 05:04 AM
  3. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 01:13 PM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 03:53 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 05:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21