title: C++ How to read string from file into std::string variable with file is FILE's pointer
body: <p>I want to read the string from file input into a <code>std::string</code> variable.<br>
  I declare a FILE pointer to open file:  </p>
  
  <blockquote>
    <p><code>FILE *f = fopen("IN.txt","r");</code>   </p>
  </blockquote>
  
  <p>And then, I read using <code>fscanf()</code> function:  </p>
  
  <blockquote>
    <p><code>std::string tempStr;</code><br>
    <code>fscanf(f,"%s",tempStr); //Compile Error</code><br>
    <code>//fscanf(f,"%s",&amp;tempStr);//Runtime Error</code></p>
  </blockquote>
  
  <p>So, I have 2 question:<br>
  1. Is it possible to fix the problem above (Still use <code>FILE *f</code> and <code>fscanf()</code> function)?<br>
  2. I'm a C programmer, new to C++. How to solve this problem with the different way?</p>
  
  <p><strong>Here is my code:</strong>  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      int n;
      string cities[100];
      FILE * f = fopen("IN.txt", "r");
      fscanf(f,"%d",&amp;n);
      for (int i=0; i&lt;n;i++)
      {
          string tempStr;
          fscanf(f,"%s",tempStr);
          cities[i] = tempStr;
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>And the input file (first line is numbers of line):</strong></p>
  
  <pre><code>8
  Vancouver
  Yellowknife
  Edmonton
  Calgary
  Winnipeg
  Toronto
  Montreal
  Halifax
  </code></pre>