+ 3
Can you hold strings inside an array??
is there any possible way to hold strings inside an array.
10 Answers
+ 6
Yes you can:
string s[10];
or
string s[] = {"hi", "there"};
+ 3
vector = array
+ 2
@teja, OĐ
vector <string> strings;
//ââ
initialize the vector
for(string temp;cin>>temp;)
strings.push_back(temp);
//ââ
while read string add it to the end of the vector
// ââ
this loop will stop when it encounters an end of file
copy(strings.begin(), strings.end(),
ostream_iterator<string>(cout, "\n"));
//ââ
it's function of simple output of the vector
Anything else?
+ 2
@teja
Vector is a wrapper for the standard array in C++. It automatically increases its size if it overflows. The vector also contains many "Goodies" as fast sorting (#include <algorithm>, std:sort) simple output. It is appropriate and proper use could make the program faster and more functional.
+ 1
String is even in the vectors can contain =)
vector <string> strings;
for(string temp;cin>>temp;)
strings.push_back(temp);
copy(strings.begin(), strings.end(),
ostream_iterator<string>(std::cout, "\n"));
+ 1
yes
+ 1
yes, in real it is very practical approach;)
0
Mr. super_s can u explain ur example in detail please
0
thank you Mr. super_s
- 1
but what does a vector means