473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using Vectors insteard of Two dimentional arrays...

10
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.....
Oct 4 '07 #1
10 2050
Savage
1,764 Expert 1GB
Can any one tell me how to use vectors insteard of two ...


so i tried to use vectors.....
How?

Savage
Oct 4 '07 #2
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. vector< vector<yourType> > myVec;
Note the spaces! They are very important.
Oct 4 '07 #3
pra1983
10
Expand|Select|Wrap|Line Numbers
  1. 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.
Oct 5 '07 #4
Ganon11
3,652 Expert 2GB
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.
Oct 5 '07 #5
pra1983
10
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'.
Oct 5 '07 #6
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. vec[i].length()
Any member in vec (vec[i] is a vector, and so it has a .length() function.
Oct 5 '07 #7
pra1983
10
Expand|Select|Wrap|Line Numbers
  1. vec[i].length()
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.....
Oct 5 '07 #8
Savage
1,764 Expert 1GB
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
Oct 5 '07 #9
Ganon11
3,652 Expert 2GB
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.
Oct 5 '07 #10
pra1983
10
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.....
Oct 5 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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,...
12
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...
25
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?
10
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...
5
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...
3
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...
3
Digital Don
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; };
5
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; //...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.