Array of Strings in C++

C++Server Side ProgrammingProgramming

Array of strings can be created in C++ using string keyword. Here we are discussing a C++ program by using this approach.

Algorithm

Begin
   Initialize the elements of array by string keyword. And take string as input.
   Print the array.
End.

Example Code

 Live Demo

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   string Fruit[3] = {"Grape", "Mango", "Orange"};
   cout <<"The name of fruits are:"<< "\n";
   for (int i = 0; i < 3; i++)
      cout<< Fruit[i]<<",";
   return 0;
}

Output

The name of fruits are:
Grape, Mango, Orange
raja
Published on 29-Mar-2019 07:24:55
Advertisements