File handling in C++
From: John Ruiz (toenails777_at_hotmail.com)
Date: 02/29/04
- Next message: Jeff Schwab: "Re: A "match" class"
- Previous message: Chris Mantoulidis: "Re: Ofstream filename variable"
- Next in thread: Jeff Schwab: "Re: File handling in C++"
- Reply: Jeff Schwab: "Re: File handling in C++"
- Reply: John Harrison: "Re: File handling in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 29 Feb 2004 03:25:36 -0800
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
- Next message: Jeff Schwab: "Re: A "match" class"
- Previous message: Chris Mantoulidis: "Re: Ofstream filename variable"
- Next in thread: Jeff Schwab: "Re: File handling in C++"
- Reply: Jeff Schwab: "Re: File handling in C++"
- Reply: John Harrison: "Re: File handling in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|