Can any one tell me how to use vectors insteard of two dimensional arrays...
I was trying to store some thousands of values in an aray but i gives me error in between saying that
" Stack is out of order in so and so ...............memory location "
so i tried to use vectors.....
10 2050
Can any one tell me how to use vectors insteard of two ...
so i tried to use vectors.....
How?
Savage
- vector< vector<yourType> > myVec;
Note the spaces! They are very important.
- vector< vector<yourType> > myVec;
Note the spaces! They are very important.
how can i enter data into that vec . and how can i access the data from the vec after filling in it.
Well, myVec is a vector, so you will just use push_back on it. But myVec is a vector holding vectors. So you need to push_back a vector onto myVec. So the way to add data to myVec is to build a temporary vector with any data you want, and then push_back this vector.
Once you have built the vector of vectors, access data just like you would a 2-dimensional array.
Well, myVec is a vector, so you will just use push_back on it. But myVec is a vector holding vectors. So you need to push_back a vector onto myVec. So the way to add data to myVec is to build a temporary vector with any data you want, and then push_back this vector.
Once you have built the vector of vectors, access data just like you would a 2-dimensional array.
vec ---- vector in vector
vec1----- vector which is pushedback into vec
I am pushing back different size vec1's into vec. can u tell me how to check the length or size of each vector in 'vec' while accessing 'vec'.
Any member in vec (vec[i] is a vector, and so it has a .length() function.
Any member in vec (vec[i] is a vector, and so it has a .length() function.
how to clear the elements of the vector which has elements.
if in previous i have
vect=0 1 2 3 4 5 6
i need to rewrite the vect to
vect= 7 8 9 10 11 12
but it is getting added up like
vect= 1 2 3 4 5 6 7 8 9 10 11 12......
how to clear the vector
i am using ".empty()" vector.. should i keep it in loop.....
how to clear the elements of the vector which has elements.
if in previous i have
vect=0 1 2 3 4 5 6
i need to rewrite the vect to
vect= 7 8 9 10 11 12
but it is getting added up like
vect= 1 2 3 4 5 6 7 8 9 10 11 12......
how to clear the vector
i am using ".empty()" vector.. should i keep it in loop.....
empty is a bool function which checks if vector is empty,if you want to delete the elements use erase instead.
Savage
pra1983:
You keep coming back here to ask more and more simple questions about vectors. Try looking at some of its documentation at www.cplusplus.com. Many, if not all, of your questions can be answered between this website and a little trial and error on your part.
pra1983:
You keep coming back here to ask more and more simple questions about vectors. Try looking at some of its documentation at www.cplusplus.com. Many, if not all, of your questions can be answered between this website and a little trial and error on your part.
I got that but it is giving me an error sayig that
"Microsoft Visual Studio
Unhandled exception at 0x00000000 in project2.exe: 0xC0000005:
Access violation reading location 0x00000000
BREAK CONTINUE ."
I got this so I swiched from two dimensional arrays to vectors.
but in vectors also i am getting the same error .....
can any one resolve this error.....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael Aramini |
last post by:
I need to represent 1D and 2D arrays of numeric or bool types in a C++
program. The sizes of the arrays in my intended application are
dynamic in the sense that they are not known at compile time,...
|
by: Dave Theese |
last post by:
Hello all,
I'm in a poition of trying to justify use of the STL from a performance
perspective. As a starting point, can anyone cite any benchmarks comparing
vectors to plain old...
|
by: rokia |
last post by:
in a project, I use many,many stl such as stack,list,vctor etc.
somewhere the vector's size is more than 2K. is this a efficient way?
|
by: spoc |
last post by:
I have been using memcpy to copy one class to another of the same type.
There are reasons why I had to do this bug am getting some odd crashes and
maybe I'm doing something dodgy copying classes...
|
by: Computer Whizz |
last post by:
I was reading through Accelerated C++ at work when I read through the first
mention of Vectors, giving us certain functions etc.
Is there any benefit of Arrays over Vectors? Since all Vectors...
|
by: John Bend |
last post by:
Hello.
Can anyone please suggest some good tutorial links where Java Vectors
and Arrays are explained and compared?
I'm a proficient programmer but fairly new to Java. Whilst I understand...
|
by: Digital Don |
last post by:
I have a problem sending the Vectors as Referencial parameters..i.e. I am having a struct vector
struct board
{
int r;
int c;
};
|
by: andrewmorrey |
last post by:
Hello,
I've got a VC++ project containing multiple classes and a main
function. In one of the class functions, it reads from a text file and
places the data into a vector;
//...
|
by: Rob |
last post by:
How would I do this?
I want to be able to handle vectors of many different types of data
and vectors that can contain any number of other vectors of data.
Currently, I have a templated...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |