How do you do it in C++?
This is what I assumed:
Code:
#include <vector>
#include <string>
using namespace std;
int main()
{
ifstream getData;
vector<string> year;
vector< vector<string> > title;
vector< vector<double> > gross;
vector< vector<string> > lastname;
vector< vector<string> > firstname;
vector< vector<int> > age;
vector< vector<char> > type;
vector<int> counter(7, 0); // 0 = L, 1 = Y, 2 = T, 3 = G, 4 = A, 5 = Q, 6 = bad input
int i, j, n;
string yearin;
string titlein;
double grossin;
string lastnamein, firstnamein;
int agein;
char typein;
bool done = false, done1 = false;
char input;
i = 0;
getData.open("moviescs105.txt");
while (!done1)
{
getData >> yearin;
if (yearin == "ENDOFFILE")
{
done1 = true;
}
else
{
year.push_back(yearin);
getData >> n;
for (j = 0; j > n; j++)
{
getData.ignore(200,'\n');
getline(getData, titlein);
title[i].push_back(titlein);
getData >> grossin;
gross[i].push_back(grossin);
getData >> lastnamein;
lastname[i].push_back(lastnamein);
getData >> firstnamein;
firstname[i].push_back(firstnamein);
getData >> agein;
age[i].push_back(agein);
getData >> typein;
type[i].push_back(typein);
}
getData.ignore(200,'\n');
i++;
}
}
getData.close();
pushing back into 1 d vector works fine. But I don't knwo how to do it for 2 dimensional ones. Am I supposed to use an itterator or something? And if so how?