C++ Error using a custom ifstream class with a variable as argument -


i using custom ifstream class

class plb_ifstream : public parallel_istream { public: plb_ifstream(); explicit plb_ifstream(const char* filename,                       std::istream::openmode mode = std::ostream::in ); ~plb_ifstream(); virtual std::istream& getoriginalstream();  bool is_open(); void open(const char* filename, std::istream::openmode mode = std::ostream::in); void close(); bool good(); private: plb_ifstream(plb_ifstream const& rhs); plb_ifstream& operator=(plb_ifstream const& rhs); private: devnullbuffer devnullbuffer; std::istream  devnullstream; std::ifstream *original; 

};

this works single file like

plb_ifstream ifile("geometry.dat"); 

however when try use variable in argument (in for-loop) like

for(plint num=1; num<4; num++) {     std::ostringstream ostr;     ostr <<num<<".dat";     std::string var = ostr.str();      pcout <<"reading geometry.."<<endl;     plb_ifstream ifile(ostr.str());     ifile >> boolmask;     pcout<<"done..."<<endl;} 

i following errors

error: no matching function call ‘plb::plb_ifstream::plb_ifstream(std::basic_ostringstream<char>::__string_type)’| note: candidates are:| note: plb::plb_ifstream::plb_ifstream(const plb::plb_ifstream&)| note: no known conversion argument 1 ‘std::basic_ostringstream<char>::__string_type {aka std::basic_string<char>}’ ‘const plb::plb_ifstream&’| note: plb::plb_ifstream::plb_ifstream(const char*, std::ios_base::openmode)| note:   no known conversion argument 1 ‘std::basic_ostringstream<char>::__string_type {aka std::basic_string<char>}’ ‘const char*’| note: plb::plb_ifstream::plb_ifstream()| note:   candidate expects 0 arguments, 1 provided| 

i did find other solutions not utilize ifstream. if there work around using ifstream them appreciate help

you need replace:

plb_ifstream ifile(ostr.str()); 

with

plb_ifstream ifile(ostr.str().c_str()); 

to c string equivalent


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -