I am having problems reading from a txt
file in c++.
The file is composed of lines, each line has a number of 4 digits that represents a year (e.g 1900) and movie titles separated by '#'.
the file's format is: number#movie title#movie title#movie title
example of lines:
1900#Sherlock Holmes Baffled#The Enchanted Drawing
1904#The Impossible Voyage
1918#Stella Maris#Mickey#Shifting Sands#A Dog's Life#Shoulder Arms
I want to read each line, save the year in a int
variable, and each movie title in an array of string. Please help.
Here is my (wrong) code:
istream& operator >>(istream &is, Cronologia &crono){
FechaHistorica fh;
int anio;
while(!is.eof()){
char c[1024];
char aux[4];
is.read(aux,4);
is.ignore('#');
anio = atoi(aux);
fh.setAnio(anio);
cout << "\n" << anio << endl;
while(is.getline(c,1024,'#')){
fh.aniadeEventoHistorico(c);
}
}
return is;
}
FechaHistorica is composed by: int n; Array of string