c++ - 您可以在字符串文字中放置中断吗?

标签 c++ newline

这是我正在使用的常量,它是这样拆分的,因为我不想滚动我的编辑器

const string PROGRAM_DESCRIPTION = "Program will calculate the amount "
"accumulated every month you save, until you reach your goal.";

int main() 
{
    cout << PROGRAM_DESCRIPTION;
    return 0;
}

当前在命令提示符中打印为

Program will calculate the amount accumulated every month you save,until you re
ach your goal.

当它打印出来时,我希望它打印在两行上,如下所示...

Program will calculate the amount accumulated every month you save,
until you reach your goal.

我不知道将 break 语句放在字符串中的什么位置,以便正确打印出来。

最佳答案

只需插入一个\n字符就可以强制换行

const string PROGRAM_DESCRIPTION = "Program will calculate the amount "
"accumulated every month you save, \nuntil you reach your goal.";

关于c++ - 您可以在字符串文字中放置中断吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21634589/

相关文章:

c++ - 为什么具有私有(private)成员的聚合不支持 C++ 大括号初始化?

c++ - 为什么构造函数调用异常后没有释放unique_ptr?

python : compare two files with different line endings

notepad++ - 当/r/n 在文本中时,如何让 Notepad++ 显示单独的行?

Excel-VBA : Unable to Insert Line Breaks

c++ - 从 C++ 中的当前目录复制文件(Windows API)

c++ - 使用 Objective-C 和 C++ 实现 X-FACEBOOK-PLATFORM 身份验证失败

c++ - 大小基于用户输入的井字棋盘

c - C 中的打印、延迟和删除当前行

python - 避免 Python 中的长代码行