title: How do I use a string in a struct instead of a char array for reading binary data
body: <p>I am reading binary data into a struct, which is working just fine.  Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct TaqIdx {
    char symbol[10];
    int tdate;
    int begrec;
    int endrec;
  }__attribute__((packed));
  
  int main()
  {
    ifstream fin("T201010A.IDX", ios::in | ios::binary);
  
    if(!fin) {
      cout &lt;&lt; "Cannot open file."  &lt;&lt; endl;
      return 1;
    }
  
    int cnt = 0;
    TaqIdx idx;
  
    while(fin.read((char *) &amp;idx,sizeof(idx))) {
      if(!fin.good()) {
        cout &lt;&lt; "A file error occurred." &lt;&lt; endl;
        return 1;
      }
  
      idx.symbol[10] = '\0';
      cout &lt;&lt; "(" &lt;&lt; idx.symbol &lt;&lt; ", " &lt;&lt; idx.tdate &lt;&lt; ", " 
           &lt;&lt; idx.begrec &lt;&lt; ", " &lt;&lt; idx.endrec &lt;&lt; ") "
           &lt;&lt; cnt++ &lt;&lt; endl;
    }
  
    fin.close();
  
    return 0;
  }
  </code></pre>
  
  <p>The first few lines of output are the following:</p>
  
  <pre><code>(A         , 20100864, 1, 35981) 0
  (AA        , 20100864, 35982, 89091) 1
  (AAPR      , 20100864, 89092, 89093) 2
  (AACC      , 20100864, 89094, 89293) 3
  (AADR      , 20100864, 89294, 89301) 4
  (AAI       , 20100864, 89302, 99242) 5
  (AAME      , 20100864, 99243, 99252) 6
  (AAN       , 20100864, 99253, 102275) 7
  (AANA      , 20100864, 102276, 102280) 8
  (AAON      , 20100864, 102281, 102592) 9
  </code></pre>
  
  <p>My question is this: is it possible to replace the C-style character array in the structure with a C++ string?  If so, can you provide an example of how I would do that.  Many thanks!</p>