如何用多行 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