title: C++: Writing to a file inside of a function, opening that file in main
body: <p>I've been trying my best to solve a little problem I have but am struggling to find a sensible solution/explanation so I was hoping someone could help?</p>
  <p>I have basically created a function which, inside, writes to a file, and I was hoping that outside of this I would be able to open that said file but I get the following error:</p>
  <blockquote>
  <p>Undefined symbol: ReadingAFile(std::__1::basic_string&lt;char,
  std::__1::char_traits, std::__1::allocator &gt;)</p>
  </blockquote>
  <p>My codes are as follows:</p>
  <p>Function:</p>
  <pre><code>void CreatingAFile(int n)
  {
      matrix_Struct matrix_A;
      matrix_A.value = n;
      matrix_A.symmetric = 1;
  
      std::ofstream writeFile;
      writeFile.open(&quot;fileToOpen.dat&quot;);
      assert(writeFile.is_open());
     
      writeFile &lt;&lt; &quot;Symmetry&quot; &lt;&lt; &quot;\n&quot;;
      writeFile &lt;&lt; matrix_A.symmetric &lt;&lt; &quot;\n&quot;;
      writeFile &lt;&lt; &quot;Number to Iterate&quot;;
      writeFile &lt;&lt; matrix_A.value &lt;&lt; &quot;\n&quot;;
  }
  </code></pre>
  <p>My main:</p>
  <pre><code>int main()
  {
      CreatingAFile(3);
      csr_matrix file3 = ReadingAFile(&quot;fileToOpen.dat&quot;);
  }
  </code></pre>
  <p>where ReadingAFile is a file from another header of mine, that runs perfectly fine - it has a function prototype:</p>
  <pre><code>matrix_Struct ReadingAFile(std::string nameOfFile);
  </code></pre>