Declaration d'une variable ofstream

Résolu
titeuf8722 Messages postés 16 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 7 août 2007 - 25 avril 2006 à 12:19
titeuf8722 Messages postés 16 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 7 août 2007 - 25 avril 2006 à 13:51
Bonjour j'ai un problème pour déclarer une variable m_fich de type ofstream. Je dois la déclarer dans ma classe CProjetprofApp pour l'utiliser pour ecrire dans un fichier.
Voici le bout de programme ou j'ai déclarer les variables :

// projetprof.h : main header file for the PROJETPROF application
//

#if !defined(AFX_PROJETPROF_H__BA79959A_3391_450E_8C8A_2226D3E447EF__INCLUDED_)
#define AFX_PROJETPROF_H__BA79959A_3391_450E_8C8A_2226D3E447EF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

/////////////////////////////////////////////////////////////////////////////
// CProjetprofApp:
// See projetprof.cpp for the implementation of this class
//

class CProjetprofApp : public CWinApp
{
public:
bool m_estOuvert;
ofstream m_fich ;//declaration de la variable
CProjetprofApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CProjetprofApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL

// Implementation

//{{AFX_MSG(CProjetprofApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

Mon problème c'est qu'il faut mettre un include qui est celui ci (#include <fstream>) mais je ne sais pas ou il faut le déclarer.Il doit falloir le déclarer dans cette partie de programme mais je ne c'est pas ou exactement :

Partie du programe ou il faut déclarer le include :

#if !defined(AFX_PROJETPROF_H__BA79959A_3391_450E_8C8A_2226D3E447EF__INCLUDED_)
#define AFX_PROJETPROF_H__BA79959A_3391_450E_8C8A_2226D3E447EF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols



Pouvez vous m'indiquer la ligne car j'ai essayé partout mais cela me génère des erreurs du type :

c:\documents and settings\julien\bureau\projetprof\projetprof.h(27) : error C2146: syntax error : missing ';' before identifier 'm_fich'
c:\documents and settings\julien\bureau\projetprof\projetprof.h(27) : error C2501: 'ofstream' : missing storage-class or type specifiers
c:\documents and settings\julien\bureau\projetprof\projetprof.h(27) : error C2501: 'm_fich' : missing storage-class or type specifiers

2 réponses

nightlord666 Messages postés 746 Date d'inscription vendredi 17 juin 2005 Statut Membre Dernière intervention 23 mai 2007 10
25 avril 2006 à 12:26
Il ne faut pas oublier de mettre "using namespace std;" en dessous de #include <fstream>.

Le code corrigé (seulement la partie du haut)
#if !defined(AFX_PROJETPROF_H__BA79959A_3391_450E_8C8A_2226D3E447EF__INCLUDED_)
#define AFX_PROJETPROF_H__BA79959A_3391_450E_8C8A_2226D3E447EF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <fstream>
using namespace std;

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols
3
titeuf8722 Messages postés 16 Date d'inscription mardi 25 avril 2006 Statut Membre Dernière intervention 7 août 2007
25 avril 2006 à 13:51
merci trop coolllllllll !!!!!
0
Rejoignez-nous