I am doing a C++ project for the university. I have to make a chronology of historical events. I have a class to save the events, called "FechaHistorica", with a set<string>
and int
as private members. The set contains strings, each string is one historical event. The int is the year when all that events happened.
The other class is called "Cronologia", with a map<int,FechaHistorica>
to store every "FechaHistorica".
The problem is with the operator << of FechaHistorica I guess. The executbale recives two .txt files with movies, and the outpout should be the union of both documents. Here is the code for the operator << os FechaHistorica:
const char SEP = '#';
ostream& operator<< (ostream& os, const FechaHistorica& e) {
os << e.getYear();
for(const_iterator p = e.eventos.begin(); p != e.eventos.end(); ++p)
os << SEP << *p;
return os;
}
The output is:
victor@victor-GL552VW:~/Documentos/Universidad/1º Cuatrimestre/Estructura de dat
os/Practicas/Practicas-ED/Práctica 4 - STL e Iteradores$ ./bin/prueba movies.txt
films.txt
Cronología leida del archivo:
0
1900#Sherlock Holmes Baffled#The Enchanted Drawing
1901#Scrooge, or, Marley's Ghost#Star Theatre
1902#A Trip to the Moon
#The Great Train Robbery Fireman
1904#The Impossible Voyage
1905#Adventures of Sherlock Holmes; or, Held for Ransom
#Humorous Phases of Funny Faces#The Story of the Kelly Gang
1907#Ben Hur#L'Enfant prodigue
#Fantasmagorie#The Assassination of the Duke of Guise#The Taming of the Shrew#The Thieving Hand
#The Country Doctoreat#Les Misérables#Princess Nicotine; or, The Smoke Fairy
1910#In Old California'
1911#Defence of Sevastopol#L'Inferno
1912#Independenţa României#The Musketeers of Pig Alley
1913#Barney Oldfield's Race for a Life#Fantômas#Raja Harishchandra#The Bangville Police
1914#Judith of Bethulia#The Perils of Pauline#Tillie's Punctured Romance
1915#A Fool There Was#Birth of a Nation#Les Vampires#The Tramp
As you can see, some years are not printed correct, the output should be:
1900#Sherlock Holmes Baffled#The Enchanted Drawing
1901#Scrooge, or, Marley's Ghost#Star Theatre
1902#A Trip to the Moon
1903#The Great Train Robbery#Life of an American Fireman
1904#The Impossible Voyage
1905#Adventures of Sherlock Holmes; or, Held for Ransom
1906#The Story of the Kelly Gang#Humorous Phases of Funny Faces#Dream of a Rarebit Fiend
1907#Ben Hur#L'Enfant prodigue
1908#Fantasmagorie#The Taming of the Shrew#The Thieving Hand#The Assassination of the Duke of Guise#A Visit to the Seaside
1909#The Country Doctor#A Corner in Wheat#Les Misérables#Princess Nicotine; or, The Smoke Fairy
1910#In Old California'
1911#L'Inferno#Defence of Sevastopol
1912#Independenţa României#The Musketeers of Pig Alley
1913#The Bangville Police#Barney Oldfield's Race for a Life#Fantômas#Raja Harishchandra
1914#The Perils of Pauline#Judith of Bethulia#Tillie's Punctured Romance
1915#Birth of a Nation#Les Vampires#The Tramp#A Fool There Was
Well, if I add endl
after every event, the output is correct, I mean, os << SEP << *p << endl;
instead of os << SEP << *p;
, but I don't want to have endl after each historical event in the output. What can I do?
I hope you can help me, thanks.
The files with data are "movies.txt" and "films.txt" The full code of the proyect is here: https://github.com/vicase/Practicas-ED/tree/master/Pr%C3%A1ctica%204%20-%20STL%20e%20Iteradores