[débutant]Pb de structure du programme
J'ai fais pendant un an des applications C++ graphiques avec un RAD et n'étant pas satisfais par ma compréhension du language je reviens aux bases. Et je galère pour gérer tout seul la structure d'un programme sensé lire/écrie dans un fichier texte (j'essaie de me familiariser avec les class).
Voici mon fichier.h :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #ifndef FICHIER_H
#define FICHIER_H
#include <string>
class Fichier
{
public:
Fichier(); //constructeur
//déclaration des variables
std::string strPath;
std::string strMsg;
//déclaration des fonctions
void lecture(const std::string& strPath);
void ajouter(const std::string& strPath, const std::string strMsg);
~Fichier(); //destructeur
};
#endif |
Et mon fichier.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <string>
#include <fstream>
#include <iostream>
#include "fichier.h"
using namespace std;
void Fichier::lecture(const std::string& strPath);
{
ifstream fichier(strPath);
if(fichier)
{
string ligne;
while(getline(fichier, ligne))
{
cout << ligne << "\n";
}
}
}
void Fichier::ajouter(const std::string& strPath, const std::string strMsg);
{
//ajoute une ligne de commentaire au log
ofstream fichier(strPath, ios_base::app);
fichier << strMsg << "\n";
}
int main()
{
char command[2];
cin >> command;
if(command == 'l')
{
string strPath;
cout << "entre le path du fichier :\n";
cin >> strPath;
Fichier::lecture(strPath);
}
return 0;
} |
Pour le moment j'utilise seulement la fonction de lecture et lorsque je compile, il me dit, parmi d'autres erreurs, que la déclaration des fonctions Fichier::ajouter et Fichier::lecture à l'extérieur n'est pas une définition.
Evidement je n'y comprend rien.
Quelqu'un pourrait mettre en évidence mes erreurs ?
Re: [débutant]Pb de structure du programme
J'ai pas le temps de tout commenter. Ton problème est que les ; à la fin
des deux lignes suivantes sont de trop.
Citation:
Envoyé par Tymk
Et mon fichier.cpp
Code:
1 2 3 4 5 6 7 8 9
|
void Fichier::lecture(const std::string& strPath);
{
...
}
void Fichier::ajouter(const std::string& strPath, const std::string strMsg);
{
...
} |