|
-
April 11th, 2002, 10:52 PM
#1
Vectors and Files
hi.
i need to write a STL vector to a file, but i want to do that in a single line, that is, not by iterating the vector. is there some STL function enabling me to do so?
thanks in advance.
-
April 13th, 2002, 03:53 PM
#2
Re: Vectors and Files
yes there is. It is called ostream_iterator, and you use copy, thus:
std::copy( v.begin(), v.end(), std: stream_iterator<T>( ofs, sep ) );
where v is your vector, ofs is your open output file stream, T is the type in your vector and sep is a string separator. (sep can definitely be char *. Maybe it can also be std::string but I'm not sure).
If ofs is a wide-character output stream, use ostream_iterator< T, wchar_t > and use a wide-string separator.
The best things come to those who rate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|