#include "lib2.h" main(int argc, char **argv) { Song chanson; Album disque, *d; Artist artiste; Artist *a, partiste; map albums; map ::iterator ait; map artists; map ::iterator arit; vector lines(0); string s; int i; ifstream infile(argv[1]); ofstream ouf("tmpfile"); ofstream ouf2("tmp2"); while (!infile.eof()) { getline(infile, s); if (!infile.fail()) lines.push_back(s); } for (i = 0; i < lines.size(); i++) { stringstream iss,iss2; iss2.clear(); iss.str(lines[i]); iss2.str(chanson.time); iss >> chanson.title >> chanson.time >> partiste.name >> disque.name >> disque.genre >> chanson.track; rep(chanson.title,"_"," "); rep(disque.name,"_"," "); rep(partiste.name,"_"," "); rep(chanson.time,":"," "); iss2.str(chanson.time); iss2 >> chanson.mins >> chanson.secs; chanson.minutes = atoi(chanson.mins.c_str()); chanson.seconds = atoi(chanson.secs.c_str()); if (ouf.is_open() && ouf2.is_open()){ ouf << partiste.name <<" \n"; ouf2 << disque.name << " \n"; } } ouf.close(); ouf2.close(); string artist, disc; ifstream inf("tmpfile"); ifstream inf2("tmp2"); while(!inf.fail()) { getline(inf, artist); if (!inf.fail()) { findindex(artist); arit = artists.find(artist); if (arit == artists.end()) { a = new Artist; a->name = artist; artists.insert(make_pair(a->name, a)); } else { a = arit->second; } } } inf.close(); while(!inf2.fail()) { getline(inf2, disc); if (!inf2.fail()) { findindex(disc); ait = albums.find(disc); if (ait == albums.end()) { d = new Album; d->name = disc; albums.insert(make_pair(d->name, d)); } else { d = ait->second; } } } inf2.close(); for (arit = artists.begin(); arit != artists.end(); arit++) { a = arit->second; cout << "\n" << a->name << endl; for (ait = albums.begin(); ait != albums.end(); ait++) { cout << " " << ait->first << "\n"; } } } void rep(std::string &str, string c, string cr) { int position = str.find(c); while (position != string::npos) { str.replace(position,1, cr); position =str.find(c,position+1); } } void findindex(string var){ int index; index = var.find(" "); while (index >= 0 && var[index] == ' ') index--; var = var.substr(0, index+1); }