Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

วิธีเขียน long strings หลายบรรทัดใน C/C++


Long strings เขียนหลายบรรทัดได้โดยใช้ two double quotes ( “ “ ) ตัด string ที่จุดไหนก็ได้กลาง string

โปรแกรมสาธิตใน 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; }

ผลลัพธ์

The output of the above program is as follows.

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

เข้าใจโปรแกรมข้างต้น:

String str เขียนหลายบรรทัดได้ด้วย two double quotes ( “ “ ) ตัด string กลาง string แล้วแสดงด้วย puts Code snippet:

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