如何用多行 C/C++ 编写长字符串?


长字符串可以通过使用两个双引号( “ “ )在中间的任意位置中断字符串来写入多行。

以下是用 C 展示此功能的程序。

示例

 实际演示

#include <stdio.h>
int main() {
   char *str = "This is the method "
               "to write long strings "
               "in multiple lines in C";
   puts(str);
   return 0;
}

输出

以上程序的输出如下。

This is the method to write long strings in multiple lines in C

现在让我们来了解一下上面的程序。

可以通过使用两个双引号( “ “ )来中断字符串在中间的任意位置,从而将字符串 str 写入多行。然后使用 puts 显示字符串。以下代码段展示了这一过程。

char *str = "This is the method "
"to write long strings "
"in multiple lines in C";
puts(str);

更新于: 26-6 月-2020

13K+ 浏览量

开启你的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.