![]() |
| ||
| Creating a dynamic 2D array I have a code snippet i've been working on but not getting very far. What I have is a text file which looks like an XML but i want to get the data between the tags and ignore the tags themselves. I want to count the number of data items between the tags and create a 2D array so if for example I have this: Quote:
I think i can get the first array right but when i try and get the other bit it gives the wrong answer int d1=0, d2=1; |
| ||
| Re: Creating a dynamic 2D array You should consider using a vector, or a list instead of bothering with an array. It would be much easier. Read the whole file line by line in a temporary string then push it back into the vector. Iterate through the vector and you will get all of the lines one by one. Then write a function, which can determinate if it is a tag(opening or closing). If it is just throw it away, or mark it with something. When you are done, all you have to do is read out, the unmarked strings. Oops I forgot, it would only work if the tags are separated with new line, otherwise you would have to make some substraction from the strings with tag. |
| ||
| Re: Creating a dynamic 2D array You should split up all the tasks into separate functions. All of it should be part of class. The file handling would probably look like this. Unless you're concerned about massive files.. if(file.is_open)You now have the contents. Time to just get where a tag ends and begins, continue to alter the attributes of the inner-most data based on these tags. |
| ||
| Re: Creating a dynamic 2D array I did think of using seperate functions to break down each bit so i'll look into that. Also with vectors can they be 2D? The reason i thought an array would be better becuase i can count the number of tags so i can set the array size but i need to get wheat is in between. Also i need to be able to reference a location of a cell and disp[lay what is in there. I have only just started using C++ so i have no clue but i have used Java before a little |
| ||
| Re: Creating a dynamic 2D array Well, a vector or list is similar to an array. They are a kind of sequence containers, and they expect real arguments. So, you can't create a list or vector, which holds lists or vectors. Read about them: http://www.cplusplus.com/reference/stl/vector/ http://www.cplusplus.com/reference/stl/list/ |
| ||
| Re: Creating a dynamic 2D array 2D enough for you? vector< vector<int> > v;Chris |
| ||
| Re: Creating a dynamic 2D array Quote:
|
| ||
| Re: Creating a dynamic 2D array Quote:
|
| All times are GMT -4. The time now is 3:39 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC