Does any know fo a routine that will load all of files characters into an array?
Printable View
Does any know fo a routine that will load all of files characters into an array?
Yes:
Code:#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
using namespace std;
void reader() {
struct _stat buf;
_stat("file.ext", &buf);
long lLen = buf.st_size;
char *pcBuf = new char[lLen+1];
ifstream inFile("file.ext");
if(inFile.good()) {
inFile.read(pcBuf, lLen);
}
pcBuf[lLen] = 0; // Null-terminate, just in case
// Use array
delete[] pcBuf;
}