deliciousMammal
Registered
Hello C++ coders.
I was just wondering about good coding style for inputting files of unknown length into a variable. Currently I have something like this:
ifstream file;
file.open(filePath);
while (file) {
++length;
file.get();
}
And then I use new to initialize an array of chars and then close the file, reopen it, and go through it for length times setting each member of the new array as I go.
Is there a better way to do this? I figure there probably is, so any help would be appreciated. Thanks.
I was just wondering about good coding style for inputting files of unknown length into a variable. Currently I have something like this:
ifstream file;
file.open(filePath);
while (file) {
++length;
file.get();
}
And then I use new to initialize an array of chars and then close the file, reopen it, and go through it for length times setting each member of the new array as I go.
Is there a better way to do this? I figure there probably is, so any help would be appreciated. Thanks.