can anybody please explain why I am getting all the junk at the end of buffer1?
#include <iostream>#include <fstream>using namespace std;int main(){ ifstream fin("index.html", ios_base::binary | ios_base::in); fin.seekg(0, ios::end); int length = fin.tellg(); fin.seekg(0, ios::beg); char *buffer1 = new char[length]; fin.read(buffer1, length); char buffer2[] = "12345"; char *buffer3 = "12345"; cout << buffer1 << endl; cout << buffer1[0] << buffer1[1] << buffer1[2] << buffer1[3] << buffer1[4] << endl; cout << buffer2 << endl; cout << buffer3 << endl; system("pause"); return 1;}
the file contains "12345" no spaces, no returns.
and this is the output I get:
Quote:
12345²²²²½½½½½½½½■¯■¯■¯■
12345
12345
12345
Press any key to continue . . .
how is it that buffer1 is exactly 5 bytes, AND I can print each character individually, but when I try and use cout on it, I get all kinds of junk at the end?