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;
} |
Partager