### Beginner vector question

So I was under the impression that using vectors would allow the user to specify the size of the vector during program execution and it does....but only if I make the vector size bigger than what the user enters. Is there a way for the user to specify the size of the vector without having me making the vector ridiculously huge to accommodate the user. I know arrays can't do it which is why I am trying to learn vectors. Thanks for any feedback!

 ``1234567891011121314151617181920212223242526272829303132333435`` ``````//VECTOR program...messing around //book says user can specify vector size...unlike arrays where they are static #include "iostream" #include "string" #include using namespace std; int main() { int j,vectorSize=500; cout<<"-- Outputting a vector --"< intList(vectorSize); //user gets to specify however many numbers he/she wants cout <<"How mnay numbers will you be using: "; cin >>vectorSize; cout<>intList[j]; } //output numbers cout<
 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````#include "iostream" #include "string" #include using namespace std; int main() { cout<<"-- Outputting a vector --"<>vectorSize; cout< intList(vectorSize); // STATIC ARRAY int aList[vectorSize]; //user inputs numbers for(int j=0;j>intList[j]; // or: cin>>aList[j]; aList[j] = intList[j]; } //output numbers cout<
Don't know much about vectors, but you posted in the wrong thread. This should have been in Beginner C++ or General C++ but not Jobs.
Silly me. Thanks. Was wondering why I couldn't find my code in the beginners section. Thanks zegarek84
Topic archived. No new replies allowed.