GhettoBusta
Legacy Member
Anyone good enough in C++ to help me out with this?
The lines I put in red are where the problem seems to be
This is suppose to write in the string "titre", whatever the user enters. Then, with a loop, the string is transferred to characters (Nouveau.titre) ... which comes from:
struct type_chanson {
char titre[31], artiste[31], album[31], commentaires[31], annee[5];
int genre, identificateur;
};
type_chanson Nouveau;
Nouveau.identificateur = noIdentificateur;
I have two ideas:
-Either I am not accessing each character of the "titre" string right (titre is maybe not the good way)
-Either I can't use: Nouveau.titre... but then, how would I access each character in Nouveau.titre
The lines I put in red are where the problem seems to be
Code:
#include <iostream>
#include <fstream>
#include <string>
struct type_chanson {
char titre[31], artiste[31], album[31], commentaires[31], annee[5];
int genre, identificateur;
};
using namespace std;
int EnTete(int noIdentificateur)
{
string titre = "", artiste = "", album = "", annee = "", commentaires = "";
ofstream F_sortie;
F_sortie.open("listemp3.bin", ios::out | ios::binary);
if (F_sortie.fail()) {
cout << "Impossible d'ouvrir le fichier" << endl;
}
else
{
type_chanson Nouveau;
Nouveau.identificateur = noIdentificateur;
cout << "Veuillez entrer le titre de la chanson" << endl;
[COLOR="Red"] getline(cin, titre);
for (unsigned int i = 1; i <= 29; i++) {
Nouveau.titre[i] = titre[i];
}[/COLOR]
cout << "Veuillez entrer l'artiste de la chanson" << endl;
cin >> Nouveau.artiste;
cout << "Veuillez entrer l'album sur lequel se retrouve chanson" << endl;
cin >> Nouveau.album;
cout << "Veuillez entrer l'annee de parution de la chanson" << endl;
cin >> Nouveau.annee;
cout << "Veuillez entrer les commentaires qui portent sur la chanson" << endl;
cin >> Nouveau.commentaires;
cout << "Veuillez entrer le genre de la chanson" << endl;
cin >> Nouveau.genre;
cout << endl;
F_sortie.seekp(0,ios::end);
F_sortie.write((char*)&Nouveau, sizeof(type_chanson));
}
F_sortie.close();
return(0);
}
int AfficheEnTete()
{
return(0);
}
void main(void)
{
int choix = 0, noIdentificateur = 0;
do
{
cout << "Quelle operation desirez-vous effectuer? " << endl;
cout << " 1. Entrer l'en-tete d'un fichier audio " << endl;
cout << " 2. Afficher toutes les en-tetes que contient la base de donnee " << endl;
cout << " 3. Afficher le nombre de fichiers audio d'un genre donne " << endl;
cout << " 4. Afficher l'en-tete d'un fichier audio a partir de son no. d'identification " << endl;
cout << " 5. Quitter " << endl;
cout << "Selection : ";
cin >> choix;
cout << endl;
switch(choix)
{
case 1 :
noIdentificateur++;
EnTete(noIdentificateur);
break;
case 2 :
AfficheEnTete();
break;
case 3 :
break;
case 4 :
break;
default:
break;
}
}
while(5 != choix);
}
struct type_chanson {
char titre[31], artiste[31], album[31], commentaires[31], annee[5];
int genre, identificateur;
};
type_chanson Nouveau;
Nouveau.identificateur = noIdentificateur;
I have two ideas:
-Either I am not accessing each character of the "titre" string right (titre is maybe not the good way)
-Either I can't use: Nouveau.titre... but then, how would I access each character in Nouveau.titre