You can also use the STL
If you are working with binary data, make sure to open the file with ios::binary mode.Code:#include <algorithm> #include <fstream> #include <string> ... std::string mystring; ... file1 >> noskipws; while (file1) { mystring.clear(); copy_n( back_inserter( mystring ), 350, istream_iterator <char> ( file1 ) ); mystring = my_function( mystring ); file2 << mystring; }
You may not have the copy_n() template function. (Apparently it wasn't part of the last standard, alas.) Here it is:
Hope this helps.Code:template < typename InputIterator, typename SizeType, typename OutputIterator > inline OutputIterator copy_n( InputIterator first, SizeType count, OutputIterator result ) { for (; count > 0; --count) *result++ = *first++; return result; }
[edit] Yeah, that fstream doesn't take std::string thing always gets me too... But you can always say:
Heh...Code:ifstream foo( filename.c_str() );




Reply With Quote