- Posted By: pradeeshtet
- Comments: 0
simple c++ program to explain string array using an example code. Know how to use string array in c++. String array is used when, we need a group of same data type (string).
Save the below program as StrA.cpp. C++ files should have cpp extension.
To compile and execute the program. Follow the below instructions.
#include<iostream> using namespace std; int main() { int num; string beve[5] ={"coke","pepsi","bovonto","maza","limca"}; for(int j=0;j<5;j++) { cout<<j+1<<"-"<<beve[j]<<endl; } cout<<"Select a beverage"; cin>>num; cout<<beve[num-1]<<endl; return 0; }
TO comiple and execute c++ program in linux system:
Compile the c++ program using the below command, open the terminal window an type.
$> c++ StrA.cpp
To run and check the output.
$> ./a.out
TO comiple and execute c++ program in windows system:
You can use either turbo c or anyother software.