如何用多行 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);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP