Fonction de lecture de fichier (variable)
Bonjour,
Une class 'PPM' contient la fonction suivante
Read(const string& );
je voudrais la rendre en une fonction de lecture de fichier de maniere a ce que quand j'appelle Read(nomdefichier); que ca se lise d'une maniere normale.
alors je fais
Code:
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#incude <fstream>
using namespace std;
void PPM::Read(const string& fname){
ifstream fp;
fp.open(fname); //ne compile pas
} |
Une erreur de compilation :
Citation:
sfg:hydra23 ~/lab2a> make <- 1:03PM
g++ -g -c ppmutils.cpp
ppmutils.cpp: In member function âvoid PPM::Read(const std::string&)â:
ppmutils.cpp:12: error: no matching function for call to âstd::basic_ifstream<char, std::char_traits<char> >::open(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)â
/usr/include/c++/4.2/fstream:517: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
make: *** [ppmutils.o] Error 1
quand j'indique un fichier sans variables genre: fp.open("fichier23.txt"), ca compile parfaitement.
Des idees ?