J
John Ruiz
Hello everyone. I find it amazing how in C++ that reading in files still
more or less requries usage of char * type. I know there's getline to use
std::string, but the basic_stream::get methods don't work with std::string.
I would like to create a function perhaps something like:
void read(std::string &s, int numBytes);
where the user passes in s to have numBytes of data read from a file into s.
Well, this would require me to do a thing like allocate memory of char bytes
and then do a copy over to the string. So, for this reason, I find myself
sticking to doing the C thing and using FILE pointers and all because to me,
it seems like a waste to read into a char array, then copy over to
std::string, so to avoid that copy, I just do the C thing.
So, am I unaware of a way around this problem? Thanks in advance.
John
more or less requries usage of char * type. I know there's getline to use
std::string, but the basic_stream::get methods don't work with std::string.
I would like to create a function perhaps something like:
void read(std::string &s, int numBytes);
where the user passes in s to have numBytes of data read from a file into s.
Well, this would require me to do a thing like allocate memory of char bytes
and then do a copy over to the string. So, for this reason, I find myself
sticking to doing the C thing and using FILE pointers and all because to me,
it seems like a waste to read into a char array, then copy over to
std::string, so to avoid that copy, I just do the C thing.
So, am I unaware of a way around this problem? Thanks in advance.
John