+ 3
Can arrays store strings?
In examples, string in arrays not discussed
12 Respuestas
+ 3
Hello
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/#
+ 2
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
+ 2
yes it can store strings. there is a.predefined function for it
+ 1
yes, it can
+ 1
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)
+ 1
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)
+ 1
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.
+ 1
yes array store strings
0
@juarez and how?
0
@Guerra your english is excellent, just show me an example please
0
@Guerra how to add a string in it or declare it with a string inside?
0
@Guerra Thanks but if anybody has more clarifications, just jot them down here. (don't consider this closed.)