std::endl in a string variable?

前端 未结 4 2039
青春惊慌失措
青春惊慌失措 2021-01-18 16:03

Hi i want to save multiply lines in a string. I got a string logstring and i want to save multiplay error logs which i later can print in a txt file or as a console output.

4条回答
  •  耶瑟儿~
    2021-01-18 16:38

    Don't forget std::endl adds a new line and flushes the buffer.

    If you simply want new lines, \n, add them to your string, using + or stream them to a stream, using << '\n'.

    For example,

    std::string logstring;
    logstring = logstring + "Error Message" + "Number" + "Time + Date";
    logstring += '\n';
    

提交回复
热议问题