Do not put anything between the lines. Part of the C ++ vocabulary phase is to combine adjacent string literals (even over new lines and comments) into one literal.
#include <iostream> #include <string> main() { std::string my_val ="Hello world, this is an overly long string to have" " on just one line"; std::cout << "My Val is : " << my_val << std::endl; }
Note that if you want to use a new line in a literal, you will have to add this:
#include <iostream> #include <string> main() { std::string my_val ="This string gets displayed over\n" "two lines when sent to cout."; std::cout << "My Val is : " << my_val << std::endl; }
If you want to mix the #define d integer constant into a literal, you will need to use some macros:
#include <iostream> using namespace std; #define TWO 2 #define XSTRINGIFY(s) #s #define STRINGIFY(s) XSTRINGIFY(s) int main(int argc, char* argv[]) { std::cout << "abc" // Outputs "abc2DEF" STRINGIFY(TWO) "DEF" << endl; std::cout << "abc" // Outputs "abcTWODEF" XSTRINGIFY(TWO) "DEF" << endl; }
There's some kind of weirdness about how the processor gating operator works, so you need two macro levels to get the actual TWO value to convert to a string literal.
Eclipse 04 Oct '10 at 21:15 2010-10-04 21:15
source share