Question en c++
Résolu
SHILI0
Messages postés
8
Statut
Membre
-
SHILI0 Messages postés 8 Statut Membre -
SHILI0 Messages postés 8 Statut Membre -
salut a tout,
je veux lire des entiers séparés par une tabulation '\t' mis dans un fichier d'entré en c++
exemple de fichier d'entrée:
1 4
1 15
5 15
122 8
12 13
12 18
13 7
17 4
1722 5
17 1811
18 12
1810 1300
je travail avec l'idée de parcourir le ligne et stocké la valeur qui est avant la tabulation dans un variable et l'entier après la tabulation dans un autre variable.
voila mon code qui ne fonctionne pas correctement
string in_fichier;
ifstream f1(in_fichier.c_str());
f1.open(in_fichier.c_str());
string entier1;
string entier2;
istringstream fluxE1;
istringstream fluxE2;
int e1;
int e2;
while (getline(f1,l)) //tant que l'on trouve des lignes dans le fichier
{
for ( i=0; l[i]!='\t'; i++) //on prend le premier entier de la ligne
{
entier1[i]=l[i];
}
fluxE1.str(entier1.c_str());
fluxE1>>e1;
fluxE1.clear();
for ( j=1 ;l[j]!='\0'; j++) //puis le 2eme apres la tabulation
{
entier2[j-1]=l[j];
}
fluxE2.str(entier2.c_str());
fluxE2>>e2;
fluxE2.clear();
je veux lire des entiers séparés par une tabulation '\t' mis dans un fichier d'entré en c++
exemple de fichier d'entrée:
1 4
1 15
5 15
122 8
12 13
12 18
13 7
17 4
1722 5
17 1811
18 12
1810 1300
je travail avec l'idée de parcourir le ligne et stocké la valeur qui est avant la tabulation dans un variable et l'entier après la tabulation dans un autre variable.
voila mon code qui ne fonctionne pas correctement
string in_fichier;
ifstream f1(in_fichier.c_str());
f1.open(in_fichier.c_str());
string entier1;
string entier2;
istringstream fluxE1;
istringstream fluxE2;
int e1;
int e2;
while (getline(f1,l)) //tant que l'on trouve des lignes dans le fichier
{
for ( i=0; l[i]!='\t'; i++) //on prend le premier entier de la ligne
{
entier1[i]=l[i];
}
fluxE1.str(entier1.c_str());
fluxE1>>e1;
fluxE1.clear();
for ( j=1 ;l[j]!='\0'; j++) //puis le 2eme apres la tabulation
{
entier2[j-1]=l[j];
}
fluxE2.str(entier2.c_str());
fluxE2>>e2;
fluxE2.clear();