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
    21,437
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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