CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 1999
    Location
    UK
    Posts
    90

    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.


  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    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
  •  





Click Here to Expand Forum to Full Width

Featured