Can arrays store strings?
7/1/2016 7:03:22 PM
Abdur-Rahmaan Janhangeer
12 Answers
New AnswerHello Just include <string> and follow this steps: std::string str[2] = {"str1","str2"}; <string> it's a class template Check this sample in my profile: https://code.sololearn.com/cY87LGpWyUud/#
okay thanks struct array{ char string [10]; }; void main(){ array A[10]; } obviously you have to write all the libraries and stuff, but that's the idea, here you see you have the array "A" and every element of the array "A" has inside a string (BTW to access to the string you'll have to use A.string[]) hope I helped , let me know if I didn't make myself clear
yes, if you know how to use structures, all you need to do is create a structure with strings inside of it and then declare an array with those structures (I don't know if that's clear enough, sorry English isn't my first language)
okay, let's see : the string is inside the structure okay? and what we are doing is declaring an array where every element is a structure,and inside that structure you'll have a string. so just by declaring array A[10] (following my example)you are stating that every element of the array A will be a structure type (a structure "array"(and that's just a random name ) to me more exact) and in that structure it's only declared a string so to access that string you'll have to use A[x].string (BTW I was wrong in the first example this is the way to use it)
yes. a string is nothing but a character array void main () { char a[10],I; cout<<" enter a string"; for(I=0;I<5;I++) cin>>a[I]; cout<<"the strings are"; for(I=0;I<5;I++) cout<<a[I]; } sample run: enter a string dhanu Manu janu gagan Ravi the strings are dhanu manu janu gagan ravi this is how the arrays works.
@Guerra Thanks but if anybody has more clarifications, just jot them down here. (don't consider this closed.)