Qt 中如何输出回车符
在 Qt 中,可以使用 \n 或 endl 输出回车符。
使用 \n
可以使用 \n 在字符串中插入回车符。
QString str = 'Hello\nWorld'; // 在字符串中插入回车
qDebug() << str; // 输出字符串
使用 endl
可以使用 endl 在 QTextStream 中输出回车符。
qDebug() << 'Hello' << endl << 'World'; // 输出 'Hello' 和 'World',并在它们之间插入回车
以上代码将输出以下结果:
Hello
World
Hello
World
总结
使用 \n 和 endl 都可以输出回车符,选择哪种方法取决于具体情况。\n 可以直接在字符串中使用,而 endl 需要在 QTextStream 中使用。
原文地址: https://www.cveoy.top/t/topic/nS0m 著作权归作者所有。请勿转载和采集!