[lug] any c++ developers?
D. Stimits
stimits at idcomm.com
Sat Jun 30 15:23:27 MDT 2001
lpotter wrote:
>
> At 13:42 6/30/2001 -0600, you wrote:
>
> >It depends on what the problem is. What is the question? Otherwise I
> >have to answer "42".
>
> :D
>
> I'm looking for a work around until qt 3 comes out, I suppose (unless they
> haven't fixed it yet).
> I am using QT's http code, that's not quite ready for prime time yet, and
> when downloading anything using it, it outputs the servers response with
> the file, as an array of bytes. I can't quite figure out how to delete, or
> remove, or not write to disk the first bytes up till a "\n\n" gets there.
> Such as removing the first 61 bytes of the
> array/file/stream/bytes/bits/electrotronic gizmos.
> I thought about just writing a temp file, closing it, opening it again and
> just not read the first bytes up to "\n\n", and writing it as my file. But
> that seems wasteful.
> I am just brain dead on this one.
>
> thanks-
> ljp
>
There are a lot of ways around that. In some cases you'll be concerned
with efficiency, but this doesn't sound like a major efficiency issue.
In other cases you'll be concerned with security (against buffer
overflows). Probably important is to know what format you want the data
to be represented as when done...what you'll be doing with it. For
example, you might be interested in using functions that require an
array of char, or you might not have that restriction, and be able to
store it any useful way. My favorite for something like this would
probably be one of the STL (really just part of C++ std lib now, but STL
sort of connotes a specific subset) containers. If you want to do string
style manipulations, std::string is extremely nice to work with, and
avoids a lot of buffer overflow possibilities. std::vector is very close
to a normal array, but has more utility to it, such as being able to
arbitrarily grow it or erase elements (not just removing its value, but
collapsing the whole vector), while still referring to elements with
array notation. std::string also allows similar abilities, but adds
search and manipulation utility that is useful for text. If you require
unicode, there is even a way to use that with string (the wchar template
type). Let's say that you have already taken your array and stored its
values in std::string myString:
const char* token = "\n\n";
std::string::size_type index = myString.find( token );
/* if index == myString.npos then token was not found.
* if index == ( myString.length() - strlen(token) ) then token
* was at the end of string and not relevant (index is
* zero-based).
*/
myString = myString.substr( index, myString.npos );
"npos" is just 1 beyond the end of the internal storage, i.e., the first
position not contained in the data.
Another alternative which is useful for applications that get much
larger is a string stream, but it'll add more complexity initially.
string streams are very nice to work with though once they are created,
they can automatically deal with things like embedded control
characters, dotting the i's, and crossing the t's (metaphorically).
D. Stimits, stimits at idcomm.com
More information about the LUG
mailing list