Hi,
I`m reading chars to a char *buffer
Code:ifstream datafile; int length; char * buffer; try { datafile.open(filename, ios::binary ); if(!datafile.is_open()) return false; char * buffer; datafile.seekg (0, ios::end); length = datafile.tellg(); datafile.seekg (0, ios::beg); // allocate memory: buffer = new char [length]; // read data as a block: datafile.read(buffer,length); // close file datafile.close(); } catch(...) { cout<<"\n\nError occurred while reading file\n\n"; }
the contents of the test.txt file
and this is what the buffer containsCode:ksjdhafkjasnbdfkjhsdfjbsvdkjsdhgkjdshg asdasd asdasd asdasd g g
How do I fix the code to get rid of that rubbish in the end?Code:ksjdhafkjasnbdfkjhsdfjbsvdkjsdhgkjdshg asdasd asdasd asdasd g gH=.;%D




Reply With Quote