473,513 Members | 2,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multidimensional arrays (vector)

It would be great if someone could give me a hint
for my problem.

I create a multidimensional array:

vector< vector<string> > applications;

and then I want to write into it.

applications[0][0] = "Test";

Why do I get an segmentation fault error?
I also tried to resize the array before, but
it doesn't work.

Thank you very much for your response.
Jul 22 '05 #1
3 2009
Peter L. wrote:

vector< vector<string> > applications;

and then I want to write into it.

applications[0][0] = "Test";

Why do I get an segmentation fault error?
I also tried to resize the array before, but
it doesn't work.


applications.resize(1);
applications[0].resize(1);

applications[0][0] = "Test";
Max




Jul 22 '05 #2
In article <3c**************************@posting.google.com >,
Peter L. <pl*******@bluewin.ch> wrote:

vector< vector<string> > applications;

and then I want to write into it.

applications[0][0] = "Test";

Why do I get an segmentation fault error?
Because as far as the vector is concerned, the location applications[0][0]
doesn't exist. The vector currently has zero size, so no memory has been
allocated for actual data.
I also tried to resize the array before, but
it doesn't work.


It's hard to tell you what you did wrong, because you didn't show the code
that you tried. :-(

Someone else has already showed you how to use resize() to create the
location applications[0][0]. I'll also point out that you can set your
vector to a suitable initial size when you construct it:

vector<vector<string> > applications (numRows, vector<string>(numCols));

using suitable values for numRows and numCols. (this will make all the
rows the same size, namely numCols)

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 22 '05 #3
> I create a multidimensional array:

vector< vector<string> > applications;

and then I want to write into it.
You don't say how many items it will have. Since I haven't really
experimented with multidimensional vectors, I will give you a
onedimensional vector example:

vector<int> abc(20);

which creates 20 items. Do NOT confuse (20) with [20] because [20]
will create 20 empty vectors and you will get many error messages.
applications[0][0] = "Test";

Why do I get an segmentation fault error?
I also tried to resize the array before, but
it doesn't work.


Well, a possible reason would be because it doesn't know string size
so that i can be resized. But since I am not sure, it might not be
that.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
22450
by: James | last post by:
What's the best way of dynamically allocating a multidim array from the following: int **a = new int*; a = new int; .... and so on or: int (*a) = new int;
1
6572
by: ip4ram | last post by:
I have an old set of library,where I used malloc to allocate multidimensional(2 and 3) arrays,using only one malloc call(using void pointers).I get the size of the array in run time.Now that I am...
2
1710
by: Patrick | last post by:
Hi I have a problem in my C++ Funktion. I needed an 2 dimensional Array. For this i took a template script in order to create the array in the funktion. The Size of the Array I have to calculate...
9
6654
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
21
4153
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
5
1970
by: asdf | last post by:
I was told not to use the low-level language such as arrays which inherited from C, I want to know what can I use to substitute the C-style multidimensional arrays? Is there multidimensional vector?
4
5510
by: Gregory.A.Book | last post by:
I'm working with displaying and manipulating very large image sets. The program handles anything from 2D images to 4D RGB volumes in a time-series. I've been using dynamically allocated arrays to...
4
1695
by: tvashtar | last post by:
Hi sorry if this isn't the best place to be asking this, I need to create a vector-like container which is arbitrarily multi-dimensional, the number of dimensions has to be determined at run time....
9
4473
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7386
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,...
0
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7106
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.