Hello,
I'm trying to read a text fiel under Windows:
I know that there are other way (stringstream) to do this, but to do exercise, I'd like to solve in this way. I know that Windows use CR + LF at the end of each line and the read take out (maybe) the LF; this explains the 168 vs 181; also I know that the read doesn't put the END delimiter at the end block memory;
My problem is start when I did "cout << _buffer;" and I saw at its end there were some strange characters that weren't in the file; so I thought that they were the dirty memory....
Then, how do I have to proceed, please? Do I have to set '\0'? But wich position at? Do I have to call memset() to clear to memory?
Some hints, please....
I'm trying to read a text fiel under Windows:
Code:
long size; ifstream file (name, ios::ate); //open and goes at the end size = file.tellg(); //it takes 181 _buffer = new char [size]; file.seekg (0, ios::beg); file.read (_buffer, size); size = file.gcount(); //it takes 168 // _buffer[size] = '\0';
My problem is start when I did "cout << _buffer;" and I saw at its end there were some strange characters that weren't in the file; so I thought that they were the dirty memory....
Then, how do I have to proceed, please? Do I have to set '\0'? But wich position at? Do I have to call memset() to clear to memory?
Some hints, please....
Comment