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
|
#include <iostream>
#include <fstream>
#include <string>
char* chargement(std::string nom)
{
char* adresse = nullptr;
int taille;
std::ifstream flux(nom, std::ios::in);
if(!flux){std::cout << "fichier " << nom << " introuvable !\n";}
flux.seekg(0, std::ios::end);
taille = flux.tellg();
flux.seekg(0, std::ios::beg);
for (int i = 0; i<taille; i++)
{
flux.read(adresse+i, sizeof(char));
}
// ajouter \0
adresse[taille] = '\0';
// fermer le fichier
flux.close();
// renvoyer adresse
return adresse;
} |
Partager