title: Reading a string from a file in C++
body: <p>I'm trying to store strings directly into a file to be read later in C++ (basically for the full scope I'm trying to store an object array with string variables in a file, and those string variables will be read through something like object[0].string). However, everytime I try to read the string variables the system gives me a jumbled up error. The following codes are a basic part of what I'm trying.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  /*
  //this is run first to create the file and store the string
  int main(){
      string reed;
      reed = "sees";
      ofstream ofs("filrsee.txt", ios::out|ios::binary);
      ofs.write(reinterpret_cast&lt;char*&gt;(&amp;reed), sizeof(reed));
      ofs.close();
  
  }*/
  
  //this is run after that to open the file and read the string
  int main(){
      string ghhh;
      ifstream ifs("filrsee.txt", ios::in|ios::binary);
      ifs.read(reinterpret_cast&lt;char*&gt;(&amp;ghhh), sizeof(ghhh));
      cout&lt;&lt;ghhh;
      ifs.close();
      return 0;
  }
  </code></pre>
  
  <p>The second part is where things go haywire when I try to read it.
  Sorry if it's been asked before, I've taken a look around for similar questions but most of them are a bit different from what I'm trying to do or I don't really understand what they're trying to do (still quite new to this).</p>