0

Can we create an array of type string?

28th Apr 2016, 12:13 PM
Nick Fererr
6 Antworten
+ 8
Sure. For example: #include <iostream> using namespace std; int main() { string days[] = {"Sunday", "Monday", "Tuesday", "Wedensday", "Thursday", "Friday", "Saturday"}; cout << days[4]; return 0; }
12th May 2016, 12:51 PM
James Flanders
+ 1
Yes
10th Jun 2016, 9:21 PM
Curt
Curt - avatar
+ 1
yes why not!
13th Jun 2016, 2:23 PM
Utpal Kumar
Utpal Kumar - avatar
+ 1
you are wrong ahmed in your syntax you puted 3 elements in a 2 elements array you should put s [3] but index will be 2 because index will start from ( 0,1,2)
15th Jun 2016, 2:26 AM
Mohamed Amine chater
Mohamed Amine chater - avatar
0
ahmed, like Mohammed said, you allocated space for an array with 2 elements in it, Not three. Also, if you declare an array,and also initialize its elements in the same line, there's no need to enter the array size.. for instance: "int a[] = {1, 2};" instead of "int a[2] = {1, 2};"
24th Jun 2016, 7:47 PM
Nik
Nik - avatar
- 4
of course , you can ... for example : string s[2]= {"ahmed","mohamed","Ali"};
11th Jun 2016, 10:46 PM
ahmed osama
ahmed osama - avatar