c++ - Standard functions and operations not working in class constructor -
i trying make first class constructor , seems acting strangely. class derived filebuf
, reason, unable open in constructor. tried add cout
statement debugging, <<
operator not recognized.
#include <iostream> #include "bin.h" int main() { bin mybin("e:\temp\test.txt"); system("pause"); return 0; }
bin.h
#pragma once #include <fstream> #include <cstdlib> #include <cstring> class bin : private std::filebuf { int buffsize = 1000; char* buffer; unsigned int length; short int buffcounter; public: bin(std::string filename) { open(filename.c_str(), std::ios::in | std::ios::out | std::ios::trunc); if (!is_open()) std::cout << "error: failed open file " << filename << std::endl; //set io operations unbufferred, buffering managed manually setbuf(0, 0); //create buffer buffer = new char[buffsize]; }; virtual ~bin() { delete buffer; }; };
std::cout << "error: failed open file " << filename << std::endl;
should
std::cout << "error: failed open file " << filename.c_str() << std::endl;
std::cout
doesn't accept std::string
accept const char *
Comments
Post a Comment