Bonjour à toutes et à tous,

Je suis en train de développer cette interface :
http://cjoint.com/data/lEotkN7LpC_Appli.JPG

Je parcours des fichiers et j'affiche leurs contenus dans le ListControl "Values". Si le contenu du fichier est numérique (double), je peux ajouter un bruit (un entier) dans l'EditControl "Noise value" et le résultat (addition de la valeur ajoutée à toutes les valeurs du tableau) sera affiché dans le deuxième ListControl juste en dessous du premier.

Et si le contenu du fichier est string, j'ajoute un caractère à la fin de chaque chaine de caractères du tableau ; le résultat aussi devrait être affiché dans le deuxième ListControl.

Mon problème est qu'au moment de l'exécution (quand je choisis un fichier avec des valeurs string), le programme plante. Ce n'est pas le cas pour les fichiers contenant des valeurs numériques.

Pour ça, j'ai écrit deux fonctions :

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//méthode qui lit le fichier et affiche son contenu sous forme de tableau
bool CInterfaceDlg::LoadInputDocument(CString i_csFileName)
	{
		bool l_bResult=false;
		CStdioFile File;
		l_bResult = File.Open(i_csFileName,CFile::modeRead | CFile::typeText);
 
		if (l_bResult)
		{
 
			CString l_csReadTmp = "";
			bool l_bRead=File.ReadString(l_csReadTmp);
 
			std::string l_sTmp((LPCTSTR)l_csReadTmp);
			// C'est pas vraiment la Sol optimale
			char * pch = strtok((char *) l_sTmp.c_str(),";,");
 
			std::vector<std::string> l_vStringTokenizer;
			while(pch != NULL)
			{
				//SAVE TOKEN 
				l_vStringTokenizer.push_back(std::string(pch));
				//NEXT TOKEN 
				pch = strtok(NULL,";,");
			}
 
			CString strText;
			theCtrl.SubclassDlgItem(IDC_VALUES, this);
			//déclaration des colonnes
			m_iColonne = l_vStringTokenizer.size();
			for(unsigned int nc=0;nc< m_iColonne+1;nc++)
			{
				//TEXT permet d'avoir la chaîne en UniCode
				strText.Format(TEXT("Column %d"),nc);
				theCtrl.InsertColumn(nc,strText,LVCFMT_LEFT,70);
			}
 
 
 
			int i = 0;
			while (l_bRead)
			{
				CString strText;
 
 
 
				strText.Format(TEXT("Row %d"), i);
 
				// Insert the item, select every other item.
				theCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, i, strText,(i%2)==0?LVIS_SELECTED : 0, LVIS_SELECTED,0, 0);
 
				// Initialize the text of the subitems.
				for (unsigned int j=0;j<l_vStringTokenizer.size();j++)
				{
					strText.Format(TEXT("%s"), l_vStringTokenizer[j].c_str());
					theCtrl.SetItemText(i, j+1, strText);
 
				}
 
				//inutile si fixé dans les ressources dans le cas d'un controle CListCtrl.
				theCtrl.ModifyStyle(0,LVS_REPORT); 
 
				//pour régler la taille des colonnes
				//static_cast<CMainFrame *>(AfxGetMainWnd())->m_wndSplitter.SetColumnInfo(0,5*70,100);
 
 
				// j'affiche le contenu
				m_ListValues.AddString(l_csReadTmp);
 
				//afficher les lignes lues
				l_bRead=File.ReadString(l_csReadTmp);
 
				std::string l_sTmp((LPCTSTR)l_csReadTmp);
				// C'est pas vraiment la Sol optimale
 
				char * pch = strtok((char *) l_sTmp.c_str(),";,");
 
				l_vStringTokenizer.clear();
				while(pch != NULL)
				{
					//SAVE TOKEN 
					l_vStringTokenizer.push_back(std::string(pch));
					//NEXT TOKEN 
					pch = strtok(NULL,";,");
				}
 
				i++;
 
			}
			m_iligne = i;
 
			m_gadp.setIntputMatrixSize(m_iColonne, m_iligne);
 
			int k ,l;
			for(k=0;k<m_iColonne; k++)
			{
				std::vector<double> l_tmpColumn;
				l_tmpColumn.clear();
				for(l=0;l< m_iligne; l++)
				{
					CString l_CString = theCtrl.GetItemText(l, k+1);
					std::string l_string  = l_CString.GetBuffer(0);
 
					double x = convertToDouble(l_string);
					l_tmpColumn.push_back(x);
				}
				m_gadp.pushVectorInputMatrixAsColonne(l_tmpColumn);
			}
		}
		return l_bResult; 
}
 
 
//méthode qui lit le fichier (categorical) et affiche son contenu sous forme de tableau
bool CInterfaceDlg::LoadInputDocumentCateg(CString i_csFileName)
	{
		bool l_bResult=false;
		CStdioFile File;
		l_bResult = File.Open(i_csFileName,CFile::modeRead | CFile::typeText);
 
		if (l_bResult)
		{
 
			CString l_csReadTmp = "";
			bool l_bRead=File.ReadString(l_csReadTmp);
 
			std::string l_sTmp((LPCTSTR)l_csReadTmp);
			// C'est pas vraiment la Sol optimale
			char * pch = strtok((char *) l_sTmp.c_str(),";,");
 
			std::vector<std::string> l_vStringTokenizer;
			while(pch != NULL)
			{
				//SAVE TOKEN 
				l_vStringTokenizer.push_back(std::string(pch));
				//NEXT TOKEN 
				pch = strtok(NULL,";,");
			}
 
			CString strText;
			theCtrl.SubclassDlgItem(IDC_VALUES, this);
			//déclaration des colonnes
			m_iColonne = l_vStringTokenizer.size();
			for(unsigned int nc=0;nc< m_iColonne+1;nc++)
			{
				//TEXT permet d'avoir la chaîne en UniCode
				strText.Format(TEXT("Column %d"),nc);
				theCtrl.InsertColumn(nc,strText,LVCFMT_LEFT,70);
			}
 
 
 
			int i = 0;
			while (l_bRead)
			{
				CString strText;
 
 
 
				strText.Format(TEXT("Row %d"), i);
 
				// Insert the item, select every other item.
				theCtrl.InsertItem(LVIF_TEXT|LVIF_STATE, i, strText,(i%2)==0?LVIS_SELECTED : 0, LVIS_SELECTED,0, 0);
 
				// Initialize the text of the subitems.
				for (unsigned int j=0;j<l_vStringTokenizer.size();j++)
				{
					strText.Format(TEXT("%s"), l_vStringTokenizer[j].c_str());
					theCtrl.SetItemText(i, j+1, strText);
 
				}
 
				//inutile si fixé dans les ressources dans le cas d'un controle CListCtrl.
				theCtrl.ModifyStyle(0,LVS_REPORT); 
 
 
				// j'affiche le contenu
				m_ListValues.AddString(l_csReadTmp);
 
				//afficher les lignes lues
				l_bRead=File.ReadString(l_csReadTmp);
 
				std::string l_sTmp((LPCTSTR)l_csReadTmp);
				// C'est pas vraiment la Sol optimale
 
				char * pch = strtok((char *) l_sTmp.c_str(),";,");
 
				l_vStringTokenizer.clear();
				while(pch != NULL)
				{
					//SAVE TOKEN 
					l_vStringTokenizer.push_back(std::string(pch));
					//NEXT TOKEN 
					pch = strtok(NULL,";,");
				}
 
				i++;
 
			}
			m_iligne = i;
 
			m_categData.setIntputMatrixSize(m_iColonne, m_iligne);
 
			int k ,l;
			for(k=0;k<m_iColonne; k++)
			{
				std::vector<std::string> l_tmpColumn;
				l_tmpColumn.clear();
				for(l=0;l< m_iligne; l++)
				{
					CString l_CString = theCtrl.GetItemText(l, k+1);
					std::string l_string  = l_CString.GetBuffer(0);
 
					l_tmpColumn.push_back(l_string);
				}
				m_categData.pushVectorInputMatrixAsColonne(l_tmpColumn);
			}
		}
		return l_bResult; 
}
Et la méthode qui parcourt les fichiers est la suivante :
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
void CInterfaceDlg::OnBnClickedBrowse()
{
 CString OpenFilter;
 OpenFilter = "CSV File (*.csv)|*.csv||";
 
 CFileDialog FileOpenDialog(
      TRUE,
      NULL,
      NULL,
      OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
      OpenFilter,                       // filter
      AfxGetMainWnd());               // the parent window 
   if(FileOpenDialog.DoModal()==IDOK)
  {
	   // ouverture de fichier
	   m_csInputFile=FileOpenDialog.GetPathName();
 
	   LoadInputDocument(m_csInputFile);
	   LoadInputDocumentCateg(m_csInputFile);
 
	   UpdateData(false);
   }
}
Quelqu'un pourrait m'aider à corriger mon code s'il vous plait ?
Merci par avance !