I'm needing to make a class to read the entire contents of a file into a class, and then there's a function in the class that returns a char * so that it can be used by cout.
right now I have:
but I don't know what I'm doing wrong... any tips would be helpfulCode:#include <iostream> #include <fstream> #include <string> using namespace std; class FileString { private: char buff[2000]; public: // If File errors exist place them into the string buffer // which starts with **ERR: // For example, **ERR: Couldn't open file FileString (string filename) { ifstream infile(filename.c_str()); int fileSize = 0; if (!infile) { strcpy(buff, "**ERR: Could not open file!"); } else { infile.seekg(0, ios::end); fileSize = infile.tellg(); cout << fileSize << endl; for (int i = 0; i < fileSize; i++) { buff[i] = infile.get(); } } } ~FileString() { } // A call to value returns the contents of the file. const char * value() { return buff; } }; int main() { FileString temp("D:\\School\\Semester 3\\CPS271\\File IO Homework last assignment\\main.cpp"); cout << temp.value(); cin.get(); return 0; }