I have created what looks like a basic file manager class for my text engine, it compiles and runs with no warnings but it dusn't ouput the text in the file.
I have no idea how to fix it, maybe someone here could help me out with the problem.
Here is the code......
CFile_mngr.h
CFile_mngr.cppCode:#include<fstream> class CFile_mngr { public: /*CFile_mngr(); ~CFile_mngr();*/ /*function to load a file*/ void CLoad_file(std::string filename); protected: std::string filename; /*the filename*/ std::string file_contents; /*file contents to be read*/ std::ifstream fin; /*instance of ifstream*/ };
CMain.cppCode:#include "CFile_mngr.h" #include <iostream> #include <fstream> void CFile_mngr::CLoad_file(std::string filename) { fin >> file_contents; /*read the contents of the file into file_contents*/ std::cout << file_contents << std::endl; }
.....it's probably a simple problem but i can't find it :'(Code:#include "CFile_mngr.h" #include <iostream> #include <fstream> int main() { CFile_mngr CFile; CFile.CLoad_file("example.txt"); std::cin.get(); return 0; }
All help is appreciated.



LinkBack URL
About LinkBacks




. I allocate a new stream which is defaulted to the name of the file passed into the function. Streams take a c-style string and what's passed into the function is a std::string so you need to use its c_str() method.