title: passing shared_ptr to std::fstream * EDIT
body: <p>I had some problem to understand the <a href="http://www.boost.org/doc/libs/1_46_1/libs/smart_ptr/shared_ptr.htm" rel="nofollow">shared_ptr doc</a> since I am newbie in c++. I hope you could help me with my example code:</p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/multi_array.hpp&gt;
  #include &lt;boost/lexical_cast.hpp&gt;
  #include &lt;cstdlib&gt;
  #include &lt;fstream&gt;   // file I/O
  #include &lt;sstream&gt;
  
  void open_file( boost::shared_ptr&lt; std::fstream &gt; &amp;file_stream , const std::string file_name , uint8_t presition );
  
  int main( int argc, char* argv[] ) {
  
      uint32_t         num_bits = 12;
      std::fstream     *ls_coeff_p;
      boost::multi_array&lt; boost::shared_ptr&lt; std::fstream&gt; , 2&gt; ls_coeff_f( boost::extents[ num_bits ][ 2 ] );
  
      std::string  ls_coeff_file_name = "datafiles/ls_coeff";
      std::string  stable             = "_stable_";
      std::string  unstable           = "_unstable_";
      std::string  file_name_end      = ".log";
  
      for ( uint8_t i = 0; i &lt; num_bits ; i++ ) {             
              open_file( ls_coeff_f[i][0] , ls_coeff_file_name + unstable + boost::lexical_cast&lt;std::string&gt;(i) + file_name_end , 4 );
              open_file( ls_coeff_f[i][1] , ls_coeff_file_name +   stable + boost::lexical_cast&lt;std::string&gt;(i) + file_name_end , 4 );
      }
  
      // just as test case
      ls_coeff_p = ls_coeff_f[0][0];
  
      *ls_coeff_p &lt;&lt; "Hallo world!" &lt;&lt; std::endl;
  
      for ( uint8_t i = 0; i &lt; num_bits ; i++ ) {
              ls_coeff_f[i][0]-&gt;close();
              ls_coeff_f[i][1]-&gt;close();
      }
  
  }
  
  void open_file( boost::shared_ptr&lt; std::fstream &gt; &amp;file_stream , const std::string file_name , uint8_t presition ) {
  
      file_stream-&gt;open ( file_name  , std::fstream::out );
      file_stream-&gt;precision( presition );
      file_stream-&gt;setf(std::ios::fixed,std::ios::floatfield);
  
  }
  </code></pre>
  
  <p>i get the following error:</p>
  
  <pre><code> In function 'int main(int, char**)':
   Line 30: error: cannot convert 'boost::shared_ptr&lt;std::basic_fstream&lt;char, std::char_traits&lt;char&gt; &gt; &gt;' to 'std::fstream*' in assignment
   compilation terminated due to -Wfatal-errors.
  </code></pre>
  
  <p>Regards</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>after appling the suggestions of @Space_C0wb0y:</p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/multi_array.hpp&gt;
  #include &lt;boost/lexical_cast.hpp&gt;
  #include &lt;cstdlib&gt;
  #include &lt;fstream&gt;   // file I/O
  #include &lt;sstream&gt;
  
  void open_file( boost::shared_ptr&lt; std::fstream &gt; &amp;file_stream , const std::string file_name , uint8_t presition );
  
  int main( int argc, char* argv[] ) {
  
       uint32_t         num_bits = 12;
       std::fstream     *ls_coeff_p;
       boost::multi_array&lt; boost::shared_ptr&lt; std::fstream&gt; , 2&gt; ls_coeff_f( boost::extents[ num_bits ][ 2 ] );
  
       std::string  ls_coeff_file_name = "datafiles/ls_coeff";
       std::string  stable             = "_stable_";
       std::string  unstable           = "_unstable_";
       std::string  file_name_end      = ".log";
  
       for ( uint8_t i = 0; i &lt; num_bits ; i++ ) {             
            open_file( ls_coeff_f[i][0] , ls_coeff_file_name + unstable + boost::lexical_cast&lt;std::string&gt;(i) + file_name_end , 4 );
            open_file( ls_coeff_f[i][1] , ls_coeff_file_name +   stable + boost::lexical_cast&lt;std::string&gt;(i) + file_name_end , 4 );
  }
  
      // just as test case
      ls_coeff_p = ls_coeff_f[0][0].get();
  
      *ls_coeff_p &lt;&lt; "Hallo world!" &lt;&lt; std::endl;
  
      for ( uint8_t i = 0; i &lt; num_bits ; i++ ) {
          ls_coeff_f[i][0]-&gt;close();
          ls_coeff_f[i][1]-&gt;close();
      }
  
  }
  
  void open_file( boost::shared_ptr&lt; std::fstream &gt; &amp;file_stream , const std::string file_name , uint8_t presition ) {
  
      file_stream-&gt;open ( file_name.c_str()  , std::fstream::out );
      file_stream-&gt;precision( presition );
      file_stream-&gt;setf(std::ios::fixed,std::ios::floatfield);
  
  }
  </code></pre>
  
  <p>i get the following error:</p>
  
  <pre><code>t: /usr/local/include/boost/shared_ptr.hpp:315: T* boost::shared_ptr&lt;T&gt;::operator-&gt;() const [with T = std::basic_fstream&lt;char, std::char_traits&lt;char&gt; &gt;]: Assertion `px != 0' failed.
  </code></pre>
  
  <p>i debuged it a bit and found out the the problem is caused in</p>
  
  <pre><code> file_stream-&gt;open ( file_name.c_str()  , std::fstream::out );
  </code></pre>
  
  <p>also if it is not inside the function <code>open_file</code> I get the same error</p>