Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your question is a little lacking in detail, but I'm assuming that you want to save your class objects, which are in an array, to disk.</p> <p>If that understanding is correct, then the solution wouldn't seem to hard.</p> <p>I would recommend using boost::serialize for saving your classes to disk (<a href="http://www.boost.org/doc/libs/1_54_0/libs/serialization/doc/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_54_0/libs/serialization/doc/index.html</a>)</p> <p>As for your iteration process, here is an example that might help:</p> <pre><code>#include &lt;string&gt; #include &lt;vector&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/scoped_array.hpp&gt; class PrettyPetunia { public: PrettyPetunia(){;} ~PrettyPetunia(){;} private: std::string _myName; }; typedef boost::shared_ptr&lt;PrettyPetunia&gt; PrettyPetuniaPtr; typedef std::vector&lt;PrettyPetuniaPtr&gt; PrettyPetunias; typedef PrettyPetunias::iterator PrettyPetuniasItr; void SaveClassObjectOutToDisk(const char* fileName, PrettyPetuniaPtr classObjectToSave); void IterateArrayToSaveToDisk(PrettyPetunias&amp; petunias) { unsigned int loopCounter = 0; for (PrettyPetuniasItr itr = petunias.begin(); itr != petunias.end(); ++itr ) { boost::scoped_array&lt;char&gt; fileName ( new char[1024] ); // 1024 or PATH_MAX, your choice sprintf(fileName.get(), "data%d02.txt", loopCounter); PrettyPetuniaPtr ptr = (*itr); SaveClassObjectOutToDisk(fileName.get(), (*itr) ); } } void SaveClassObjectOutToDisk(const char* fileName, PrettyPetuniaPtr classObjectToSave) { // ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload