Stefan
Fri Jun 01 05:08:20 CDT 2007
On 6/1/2007 10:42 AM, Ananya wrote:
>
> "Igor Tandetnik" wrote:
>
>> "Ananya" <Ananya@discussions.microsoft.com> wrote in message
>> news:A6CF1795-D246-412B-8835-3F858F4287A3@microsoft.com
>>> I want to use an argument of type *char and an argument of type int
>>> (indicating the length of the character array) for the read method of
>>> ifstream.
>>>
>>> However, the length of my character array is variable.
>>>
>>> So I am declaring
>>> vector<char> chars
>>>
>>> But I cannot use this as the first argument of read.
>> vector<char> chars;
>> int size = ...;
>> chars.resize(size);
>>
>> ifstream ifs = ...;
>> ifs.read(&chars.front(), size);
> Wow, this works perfectly! Thanks lot!
> It's amazing that I could not find this answer in any of my C++ books.
> Do you know of any C++ book that does contain this answer?
>
It's a little bit hidden in Scott Meyers' "Effective STL", Item 16:
"Know how to pass vector and string data to legacy APIs"
Regards,
Stefan
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post
http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please
http://www.expita.com/nomime.html