I'm trying to create a program that reads content from a file with the following format:
Title
Year Gross Studio
List of Actors/Actresses (separated by a "," [up to 5])
I understand that vectors have to be of one type, so I'll exclude Gross and consider the year a string.
I'm thinking a vector so that future contents could be added or removed;
I'm thinking 2 dim vector with 8 columns. So I want m rows and 8 columns.
How would I crate the vector and then how would I save data into it?
For example, how would I save my first title into Vector 1, row 0 column 1;
year row 0 column 2, studio row 0 column 3...
title2 row 1 column 1....etc....
If you are familiar with the vector container, you may substitute the use of the integers "i" and "ii" to move through the array in favour of the iterators that are provided as member functions of the container vector.
As for reading the file, you may need to familiarise yourself with C++ streams.
So I have to set up an array within the vector?
I thought vectors were arrays themselves, except vectors are adjustable in size.
Unless I'm misinterpreting the code you helped me out with, you had the user define my rows and columns and that kind of defeats the purpose of having a vector, from what I understand.
I'd like for my program to add a new row as needed, or detected when reading the contents from my file, and not have to be declared by the user.
The code I provided is intended to give you a feel for the technique of constructing a 2D array using the STL vector. Yes, vector will allow you to resize as you add more elements. But the point I was trying to get across is that you want to use the following declaration:
vector<vector<char *>> myAry1;
Whether you choose to resize, as I have, or instead use the vector member function "push_back" to add each record is up to you. For instance, to add a new record to the array, you could use: