# Determine array size

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 01-07-2004
trainee
Quote:

Originally posted by eth0
Thanks for the tip with the vectors. I will research that method today. Probably be back with questions though :p
However, does the vector route not require that you keep a running total of how many elements are in the array?

jlou, I am already going down the route you suggested.

I am very determined to learn this lanuage, however it is very difficult to learn with books alone.

I am probably spending around 8 hours a day now trying to learn this. If I worked at a company with programmers, I know I could learn this in a quater of the time, as an experienced programmer to refer to when your stuck, can mean the difference between 10 minutes and 1 week. Even then at the end of the week your still uncertain yu tackled something in the best way.

I will deffinitely achieve this, i'm just trying to stress how difficult it is when you are on your own. People post code and solutions on here without explaining, which just goes totaly over your head. All part of the fun though :)

Vectors are a powerful array abstraction. Use the size() member function to return the number of values in the array at any time. The push_back(string) member function also dynamically appends a value to the end of your vector.

Example usage:
Code:

```#include <iostream> #include <string> #include <vector> using std::cout; using std::endl; using std::string; using std::vector; int main(void) {     vector<string> vec; // here 'string' can be replaced with any object or simple data type     vec.push_back("Joe"); // corresponding data type     cout << vec.size();     return 0; }```
Vectors overload many of the standard library operators as well so they should behave like a standard array. For example, they still use [i] style indexing if you want to access a single member. Fool around with it and if you need more help, post.

trainee
• 01-08-2004
WDT
I just started my STL learning too and whilst I agree that vectors are the best thing for this sort of problem, I do believe you're being taught how to solve a problem at the most basic level. So instead of using vectors try working around your problems with the particular code implementation. The easiest solution I can offer to your problem is to create a static variable which you decrement and increment as you remove and insert from the array that way you just have to query the variable for the number of elements that are in the array.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12