Bonjour a tous,

Je suis entrain de programmer une application qui écrit dans un fichier avec c++
j'utilise la classe CFile.

J'ai créer au début un fichier sous cette forme
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
Fichier type 1:
 
Fichier type 2:
 
Fichier type 3:
puis je désire ajouter dans le fichier les nom des fichiers pour chaque type. il de vient sous cette forme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
Fichier type 1:
Fichier 1
Fichier 2
Fichier type 2:
Fichier 3
Fichier 4
Fichier type 3:
Fichier 5
Fichier 6
le problème c'est lorsque j'ajoute une ligne celle qui est déjà écrite s'efface. Par exemple:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
Fichier type 1:
Fichier 1
er type 2:
Le code de ma classe est le suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
CErrorManager.h

class CErrorManager
{
private:
	int m_nUnDecryptedFilesIndex;
	int m_nUnverifiedFilesIndex;
	int m_nUnvalidNistFilesIndex;
	bool m_bInitialize;
	CFile m_fLogFile;
public:
	CErrorManager(void);
	~CErrorManager(void);

	void open_log_file(CString l_strErrorFile);
	void add_undecrypted_file(CString l_strErrorFile, CString l_strUndecryptedFileName);
	void add_unverified_file(CString l_strErrorFile, CString l_strUnverifiedFileName);
	void add_unexploitable_file(CString l_strErrorFile, CString l_strUnexploitableFileName);
	void close_log_file(CString l_strErrorFile);
};

CErrorManager.cpp

CErrorManager::CErrorManager()
{
	m_nUnDecryptedFilesIndex = 0;
	m_nUnverifiedFilesIndex = 0;
	m_nUnvalidNistFilesIndex = 0;
	m_bInitialize = false;
}

CErrorManager::~CErrorManager(void)
{
}

void CErrorManager::open_log_file(CString l_strErrorFile)
{
	CFileException fileException;
	char l_szBuffer[256];
	if ( !m_fLogFile.Open( l_strErrorFile, CFile::modeCreate | 
		CFile::modeNoTruncate, &fileException ) )
	{
		TRACE( "Can't open file %s, error = %u\n",
			l_strErrorFile, fileException.m_cause );
	}
	strcpy(l_szBuffer,"Fichiers non déchiffrés :\n");
	m_fLogFile.Write(l_szBuffer, strlen(l_szBuffer));
	m_nUnDecryptedFilesIndex = m_nUnDecryptedFilesIndex + strlen(l_szBuffer);
	strcpy(l_szBuffer,"\nFichiers refusés :\n");
	m_fLogFile.Write(l_szBuffer, strlen(l_szBuffer));
	m_nUnverifiedFilesIndex = m_nUnDecryptedFilesIndex + strlen(l_szBuffer);
	strcpy(l_szBuffer,"\nFichiers inexploitables :\n");
	m_fLogFile.Write(l_szBuffer, strlen(l_szBuffer));
	m_nUnvalidNistFilesIndex = m_nUnverifiedFilesIndex + strlen(l_szBuffer);
}

void CErrorManager::add_undecrypted_file(CString l_strErrorFile, CString l_strUndecryptedFileName)
{
	if ( m_bInitialize == false)
	{
		open_log_file (l_strErrorFile);
		m_bInitialize = true;
	}
	m_fLogFile.Seek(m_nUnverifiedFilesIndex,CFile::begin);
	m_fLogFile.Write(l_strUndecryptedFileName + "\n", l_strUndecryptedFileName.GetLength()+1);
	m_nUnDecryptedFilesIndex += l_strUndecryptedFileName.GetLength()+1;
	m_nUnverifiedFilesIndex += l_strUndecryptedFileName.GetLength()+1;
	m_nUnvalidNistFilesIndex += l_strUndecryptedFileName.GetLength()+1;
}

void CErrorManager::add_unverified_file(CString l_strErrorFile, CString l_strUnverifiedFileName)
{
	int x = 0;
	x = l_strUnverifiedFileName.GetLength();
	if ( m_bInitialize == false)
	{
		open_log_file (l_strErrorFile);
		m_bInitialize = true;
	}
	m_fLogFile.Seek(m_nUnverifiedFilesIndex,CFile::begin);
	m_fLogFile.Write(l_strUnverifiedFileName + "\n", l_strUnverifiedFileName.GetLength()+1);
	m_nUnverifiedFilesIndex += l_strUnverifiedFileName.GetLength()+1;
	m_nUnvalidNistFilesIndex += l_strUnverifiedFileName.GetLength()+1;
}

void CErrorManager::add_unexploitable_file(CString l_strErrorFile, CString l_strUnexploitableFileName)
{
	if ( m_bInitialize == false)
	{
		open_log_file (l_strErrorFile);
		m_bInitialize = true;
	}
	m_fLogFile.Seek(m_nUnvalidNistFilesIndex,CFile::begin);
	m_fLogFile.Write(l_strUnexploitableFileName + "\n", l_strUnexploitableFileName.GetLength()+1);
	m_nUnvalidNistFilesIndex += l_strUnexploitableFileName.GetLength()+1;
}

void CErrorManager::close_log_file(CString l_strErrorFile)
{
	if (m_fLogFile.Open( l_strErrorFile, CFile::modeCreate | 
		CFile::modeReadWrite, NULL ) )
		m_fLogFile.Close();
}
Pouvez vous m'indiquer l'erreur.
Merci d'avance.