declaring vector values
Page 1 of 110 Replies - 2323 Views - Last Post: 02 November 2011 - 10:03 AM
#1
declaring vector values
Posted 02 November 2011 - 06:59 AM
then i want to reset the first element and store the value 4
vector <int> Storage(2) //This is to declare that my vector will have 2 values (c++)
vectorStorage.resize(4) // this will reset the 1 value and set it as 4 (c++)
can some one help me or explain how to store values in a vector and not generate random values... ?
im using c++
thx
Replies To: declaring vector values
#2
Re: declaring vector values
Posted 02 November 2011 - 07:07 AM
Jim
#3
Re: declaring vector values
Posted 02 November 2011 - 07:25 AM
vector <int> storage (1 , 2) that will copy 2 one time wont it ? (C++)
#4
Re: declaring vector values
Posted 02 November 2011 - 07:31 AM
i want to store values using vectors not arays
#5
Re: declaring vector values
Posted 02 November 2011 - 07:38 AM
Jim
#6
Re: declaring vector values
Posted 02 November 2011 - 08:09 AM
let me write the question down here it is
declare a vector storage to store objects of type int (do not specify the size of storage)
store the following values into storage : 10 28
reset the the 1st element of storage to 12
so im stuck arnt vectors suposed to be like vector <int> storage() //c++ the question sayes nothing about arrays....
#7
Re: declaring vector values
Posted 02 November 2011 - 08:19 AM
How do you insert elements into a vector?
How do you store values into a regular variable?
Show some actual code where you have tried to accomplish the objectives.
The farther you go in programming the more you will be required to be able to read and understand the documentation for the concepts you are trying to use. The links I provided are parts of the documentation for the std::vector class and have nothing to do with arrays.
Jim
This post has been edited by jimblumberg: 02 November 2011 - 08:19 AM
#8
Re: declaring vector values
Posted 02 November 2011 - 08:28 AM
to declare to values in vector i said
vector <int> Storage(2) // this declares that the vector will have 2 objects (C++)
i dont know how to declare the values to that vector
vectorStorage.resize(12) // this will reset the 1st value to 12 (c++) and this will reset 1 value not 2
thats all im geting is this wrong ?
#9
Re: declaring vector values
Posted 02 November 2011 - 08:38 AM
Quote
Does the following meet all the above requirements?
vector <int> Storage(2) // this declares that the vector will have 2 objects (C++)
No it does not. You are required to declare a vector storage but not specify the size. How do you declare a vector without specifying the size?
Your instructions mention nothing about "resizing" the vector, so why are you trying to use that construct?
Read this link: insert for how you insert elements into a vector.
Jim
This post has been edited by jimblumberg: 02 November 2011 - 08:38 AM
#10
Re: declaring vector values
Posted 02 November 2011 - 09:51 AM
that was more usefull
#11
Re: declaring vector values
Posted 02 November 2011 - 10:03 AM
Jim
|
|

New Topic/Question
Reply



MultiQuote



|