int setvbuf(FILE* qpStream, char* cpBuffer, int iMode, size_t qSize);
#include <cstdio>
int main()
{
char* cpFileName = "XoaX.txt";
// Open an ASCII text file for reading.
FILE* qpFile = fopen(cpFileName, "r");
// Check that the file was opened successfully.
if (!qpFile) {
printf("Could not open the file %s\n", cpFileName);
return 1;
}
// The can be whatever size we like
const size_t kqBufferSize = 100;
char caBuffer[kqBufferSize];
// Set the buffer for the file stream
setvbuf(qpFile, caBuffer, _IOFBF, kqBufferSize);
// Read from the file.
char caRead[50];
fscanf(qpFile, "%s", caRead);
printf("String read: %s\n", caRead);
fclose(qpFile);
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.