| | |
How to initialize a vector?
![]() |
-7
#12 Oct 14th, 2009
The problem with Dave's suggestion is all those strings are now stored in memory twice -- once in the array of std::strings and again in the vector of strings. That could be a problem if the computer is low on memory, or the array contains thousands of strings. If there is an array of std::strings then there isn't much point to using a vector to hold the same strings.
Last edited by Ancient Dragon; Oct 14th, 2009 at 11:28 pm.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
1
#13 Oct 15th, 2009
•
•
•
•
The problem with Dave's suggestion is all those strings are now stored in memory twice -- once in the array of std::strings and again in the vector of strings. That could be a problem if the computer is low on memory, or the array contains thousands of strings. If there is an array of std::strings then there isn't much point to using a vector to hold the same strings.
My "Ballpark?" example was how I understood the question neithan was asking:
“The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
-7
#14 Oct 15th, 2009
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
0
#15 Oct 15th, 2009
•
•
•
•
It doesn't -- unless the strings are read from a file, in which case your example wouldn't work either
push_back , like using a back_inserter with copy perhaps; or maybe something about writing an insert_iterator . “The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
0
#16 Oct 15th, 2009
•
•
•
•
If there is an array of std::strings then there isn't much point to using a vector to hold the same strings.
I think people would use Dave's suggestion to take the advantadges of vector but having it initialized somehow.
I'm surprised array can be inialized directly and vector not. That's kind of a weakness isn't?
0
#17 Oct 17th, 2009
•
•
•
•
I'm surprised array can be inialized directly and vector not. That's kind of a weakness isn't?
C++ Syntax (Toggle Plain Text)
int foo(int x) { int array[] = {1,2,3,4,5}; return array[x]; } char *bar(int x) { char *text[] = {"one","two","three","four","five"}; return text[x]; }
“The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
![]() |
Similar Threads
- 2D Vector && Segfaults (C++)
- How to initialize a vector of pointers? (C++)
- Made my own vector thingy (C)
Other Threads in the C++ Forum
- Previous Thread: Binning alorithm
- Next Thread: how to store input large amout of data ..help over this
Views: 1386 | Replies: 18
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c++borland c/c++ calculator char class classes code compile compiler constructor conversion convert count data delete display dll dynamic encryption error exception file files forms fstream function functions game givemetehcodez graph gui helpwithhomework homework iamthwee input int integer lazy link linker list loop math matrix member memory network newbie news number object objects opengl output parameter path pointer pointers problem program programming project random read recursion recursive reference return sort spoonfeeding string strings struct student studio template templates text time tree undefined variable vc++ vector video visual win32 window windows winsock xml






