| | |
C++ beginner, vector<> or array[] ?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I'm new to C++, and i've seen some C and C++ code.
I tried array[] and vector<> so i see i can use both, why should i use what way to work with vectors?
Furthermore, i've seen a lot of "array[]" in this forum... so, any lead?
Thank you!
Oh by the way, i'm learning with the "Principles and Practice Using C++" by Stroustrup, what do you think? I'm in the good direction? Any recommendations?
I tried array[] and vector<> so i see i can use both, why should i use what way to work with vectors?
Furthermore, i've seen a lot of "array[]" in this forum... so, any lead?
Thank you!
Oh by the way, i'm learning with the "Principles and Practice Using C++" by Stroustrup, what do you think? I'm in the good direction? Any recommendations?
5
#2 Oct 8th, 2009
•
•
•
•
I'm new to C++, and i've seen some C and C++ code.
I tried array[] and vector<> so i see i can use both, why should i use what way to work with vectors?
Furthermore, i've seen a lot of "array[]" in this forum... so, any lead?
The main problem with arrays is that you generally have to fill the array with values, when you want to use it. And this means you've first got to create the array, and you have to know what size it is, and then you have to put the values into it. Lots of times newbies on this forum will create an array _larger_ than the amount of stuff they're putting in it, and then, when it has too much stuff, they just throw an error. Or worse, they keep trying to put more stuff in, writing into memory past the end of the array, creating undefined behavior that's hard to debug. And then you've got to keep track of how much stuff you've put in the array.
With std::vector, you just create the vector, and then append stuff using push_back. So just worry about std::vector<> and std::string for now. Occasionally you'll need to use a char*, like when you need to provide a filename for opening a file. Plenty of APIs will expect arrays, though, and that's just life.
I don't know whether the book is good, but I know the author is good.
Last edited by Rashakil Fol; Oct 8th, 2009 at 6:04 pm.
All my posts may be redistributed under the GNU Free Documentation License.
0
#3 Oct 8th, 2009
•
•
•
•
I'm new to C++, and i've seen some C and C++ code.
I tried array[] and vector<> so i see i can use both, why should i use what way to work with vectors?
Furthermore, i've seen a lot of "array[]" in this forum... so, any lead?
Thank you!
Oh by the way, i'm learning with the "Principles and Practice Using C++" by Stroustrup, what do you think? I'm in the good direction? Any recommendations?
And considering Stroustrup invented C++ I'd consider it a good book though C++ The Programming Language is another good one from Bjarne
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
0
#5 Oct 8th, 2009
Last edited by ShawnCplus; Oct 8th, 2009 at 6:11 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
0
#7 Oct 8th, 2009
Awesome explanation, i think i got the idea. So i'll stick with vector and string although i'll have to it array anyways since as you say it's used in most libraries.
Thank you very much guys!
PD: i asked if i was in the good direction with this book since it's 1200 pages long! LOL (i'm at pg 140 already haha, just a few to go)
Thank you very much guys!
PD: i asked if i was in the good direction with this book since it's 1200 pages long! LOL (i'm at pg 140 already haha, just a few to go)
![]() |
Similar Threads
- need help to store coordinates in vector array (C++)
- Populating a 3d vector array (C++)
- Vector construction from an array (C++)
- Assigning a dynamic array to a vector (C++)
- vector array (C++)
Other Threads in the C++ Forum
- Previous Thread: restricting friend member function
- Next Thread: Insert loop in log file
| Thread Tools | Search this Thread |







