C ++中的字符串数组
可以使用string关键字在C++中创建字符串数组。在这里,我们正在讨论使用这种方法的C++程序。
算法
Begin Initialize the elements of array by string keyword. And take string as input. Print the array. End.
范例程式码
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
string Fruit[3] = {"Grape", "Mango", "Orange"};
cout <<"水果的名称是:"<< "\n";
for (int i = 0; i < 3; i++)
cout<< Fruit[i]<<",";
return 0;
}输出结果
水果的名称是: Grape, Mango, Orange