Récuperer des chaines de caractére spécifiques
Bonjour, je suis en train de développer un code en c++ pour un serveur de licence.
j'ai un fichier "licence.txt" que voilà :
Code:
1 2 3 4
|
Client 1/licence produit 2/30-12-2008/
Client 2/licence produit 2/30-12-2008/
Client/licence produit 3/30-12-2008/ |
et un fichier test.cpp
Code:
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
| // test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
void SupprimeTousLesCaracteres( std::string & Str, char C )
{
Str.erase(
std::remove( Str.begin(), Str.end(), C ),
Str.end() );
}
std::string SupprimeLesPremiersCaractères( const std::string & Str, char C )
{
return Str.substr(
Str.find_first_not_of( C ) );
}
int _tmain(int argc, _TCHAR* argv[])
{
std::ifstream fichier ("licence.txt");
if (fichier)
{
std::stringstream buffer;
buffer << fichier.rdbuf();
fichier.close();
std::istringstream iss (buffer.str());
std::string mot;
std::string nom;
std::cout << "nom : ";
getline(std::cin, nom);
while (std::getline(iss, mot, '/'))
{
mot = SupprimeLesPremiersCaractères(mot, '\n\r');
const char *c_mot = 0;
c_mot = mot.data( );
const char *c_nom = 0;
c_nom = nom.data( );
if (strcmp(c_mot,c_nom)== 0)
{
std::cout << mot <<" \n";
}
}
}
system ("PAUSE");
return 0;
} |
Quand le client entre son nom, le buffer retourne son nom.
J'aimerai rajouter le reste de la ligne.
exemple :
Quant le client "Client 1" tape son nom, ça affiche la ligne
Client 1/licence produit 2/30-12-2008/
mais de cette façon :
Client 1
licence produit 2
30-12-2008
Merci pour vos lumières
Si vous avez pas compris, posez des questions