If(sousligne1.compare(sousligne3))

Résolu/Fermé
yanlou Messages postés 119 Date d'inscription dimanche 30 septembre 2007 Statut Membre Dernière intervention 11 août 2010 - 10 juil. 2008 à 15:50
yanlou Messages postés 119 Date d'inscription dimanche 30 septembre 2007 Statut Membre Dernière intervention 11 août 2010 - 11 juil. 2008 à 12:51
Bonjour,
pourquoi mon code ne fonction pas correctement, le test

#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
std::string ligne = "FT;4249;D;RFRPAD8;2063à2093";
//std::string ligne = "FT;4249;D;CRAEZD2/A2;2063à2093";
{
size_t pos0=ligne.find_first_of(";");
size_t pos1=ligne.find_first_of(";",pos0+1);
size_t pos2=ligne.find_first_of(";",pos1+1);
size_t pos3=ligne.find_first_of(";",pos2+1);

size_t posSlash = ligne.find("/");

size_t posDot = ligne.rfind(";", posSlash);

size_t posDot_2 = ligne.find(";", posSlash);

std::string sousligne1 = ligne.substr(posDot+1, posSlash - posDot-1);
std::string sousligne2 = ligne.substr(posSlash+1, posDot_2 - posSlash-1);
std::string sousligne3=sousligne1.substr(0,sousligne1.size()-2).append(sousligne2);

if(sousligne1.compare(sousligne3)) // le test ne fonction pas !!
{
cout << sousligne1 << endl << sousligne3 <<endl;
}
else
{
cout<<ligne.substr(pos2+1,pos3-pos2-1)<<endl;
}
}
return 0;
}
A voir également:

1 réponse

yanlou Messages postés 119 Date d'inscription dimanche 30 septembre 2007 Statut Membre Dernière intervention 11 août 2010 13
11 juil. 2008 à 12:51
résolu
0