Splitting C++ Strings Onto Multiple Lines (Code Syntax, Not Parsing)

前端 未结 3 477
日久生厌
日久生厌 2021-01-31 13:34

Not to be confused with how to split a string parsing wise, e.g.:
Split a string in C++?

I am a bit confused as to how to split a string onto multiple lines in c++.<

3条回答
  •  醉梦人生
    2021-01-31 13:47

    I don't know if it is an extension in GCC or if it is standard, but it appears you can continue a string literal by ending the line with a backslash (just as most types of lines can be extended in this manor in C++, e.g. a macro spanning multiple lines).

    #include 
    #include 
    
    int main ()
    {
        std::string str = "hello world\
        this seems to work";
    
        std::cout << str;
        return 0;
    }
    

提交回复
热议问题