Hi.
I'm new in C++ and I need your help. I've got a structure and file in .csv format. It looks like this:
Twelve Monkeys;Sci-Fi / Thriller;USA;1995;129;Terry Gilliam;MUSIC;Bruce Willis, Madeleine Stowe, Brad Pitt;
American Gangster;Drama;USA;2007;157;Ridley Scott;Marc Streitenfeld;Denzel Washington, Russell Crowe;
Star Wars: Episode VI - Return of the Jedi;Sci-Fi / Fantasy / Action;USA;1983;134;Richard Marquand;John Williams;Mark Hamill, Harrison Ford;
Gladiator;Action / Drama / Historical;USA / GB;2000;149;Ridley Scott;Hans Zimmer;Russell Crowe;
I need to know how to search in names of movies and then get entirely line as a movie profile and some filter that can write every movie with entered value like year or genre.
I've got this so far: :D
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
int choose;
struct t_film
{
string name;
string nameEng;
string genre;
string country;
string year;
string duration;
string director;
string music;
string cast;
};
char loadFilm()
{
ifstream inFile;
t_film film;
vector <t_film> myData;
string line;
int cnt = 0;
inFile.open("in.txt");
if (inFile.is_open())
{
while(!inFile.eof())
{
getline(inFile, line, ';');
if (cnt == 0)
{
film.name = line;
cnt++;
}
else if (cnt == 1)
{
film.nameEng = line;
cnt++;
}
else if (cnt == 2)
{
film.genre = line;
cnt++;
}
else if (cnt == 3)
{
film.country = line;
cnt++;
}
else if (cnt == 4)
{
film.year = line;
cnt++;
}
else if (cnt == 5)
{
film.duration = line;
cnt++;
}
else if (cnt == 6)
{
film.director = line;
cnt++;
}
else if (cnt == 7)
{
film.music = line;
cnt++;
}
else
{
film.cast = line;
myData.push_back(film);
cnt = 0;
}
}
}
else {
cerr << "error." << endl;
}
inFile.close();
switch(choose)
{
case 1: for(unsigned int i = 0; i < myData.size(); i++)
{
cout << myData[i].name << endl;
}
break;
case 2:
for(unsigned int i = 0; i < myData.size(); i++)
{
cout << myData[i].nameEng << endl;
}
break;
default: cout << "unknown\n";
}
cout << endl;
return 0;
}
I really appreciate your advice and help. Thank You.