473,231 Members | 1,699 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,231 software developers and data experts.

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 1997
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
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
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
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
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
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
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
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
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
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
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.