Thread: Concatnating strings that are too long for one line

  1. #1
    Registered User
    Join Date
    Apr 2007

    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:
    function ("Long " +
    However apparently I can't do that.

    I also tried:
    function ("Long \
    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
    Let the compiler do the concatenation for you:
    function("Long "
    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, 06: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, 02:13 PM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM