vector <ofstream> os(0);
...
ofstream x;
os.push_back(x);
...
os[myValue].open(dav.c_str(), ios::app | ios::binary);
...
if(os[myValue].write(buffer,messageSize)){
//if(X[myValue].write(buffer, messageSize)){
cout << "written to file test" << clientSocket << endl;
}
...
Any suggestions?
Vectors and ofstream
I''m trying to write to a file, however the file to be written to depends on other data and I may need to write using several different ofstreams. Hence, the possible ofstreams are stored in a vector.
However, when I try to use the same exact code using arrays everything is fine, but when I try to do it using the vector....it''ll open and close the file ok but just won''t write anything to it.
Here''s the code....
iostreams can''t be copied, you could refer to them using a vector (create the ofstreams using new). If you don''t want to have to remember to delete the pointer use a boost::shared_ptr instead (www.boost.org).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement