Just some block of memory. People tend to use the word "buffer" when talking about moving data around, because the data will be placed in the buffer, then placed in its final destination.
That's not always the case though, but it is one of those "feels right" programmer things. :-|
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
// This is where we'll put the stuff we read from file
char buffer[ 81 ];
// Here's our file
ifstream file( "80-chars.txt" );
// Fill the buffer with zeros (char strings must be null-terminated)
fill_n( buffer, 81, '\0' );
// Read as many as 80 bytes (chars) from the file and stick them in our array
file.read( buffer, 80 );
file.close();
// Convert that char array into a STL string, and show the user what we got.
string s( buffer );
cout << s << endl;
return 0;
}
While this looks like the long way around to getting a string from file, it is actually pretty close to how getline() actually does it.
I have a question about the zeroing.
You use fill_n(pointer, size, '\0') to zero the memory of a variable.
I found from a Microsoft's example the ZeroMemory(pointer, size) command which do the same thing.
Which one you think is the best to use just to zero the variable?