title: how do I open and read a file using ifstream in C++?
body: <p>I would like to open a file and read a line from it. There will be only one line in the file so I don't really need to worry about looping, although for future reference it would be nice to know how to read multiple lines.</p>
  
  <pre><code>int main(int argc, const char* argv[]) {
  
      // argv[1] holds the file name from the command prompt
  
      int number = 0; // number must be positive!
  
      // create input file stream and open file
      ifstream ifs;
      ifs.open(argv[1]);
  
      if (ifs == NULL) {
          // Unable to open file
          exit(1);
      } else {
          // file opened
          // read file and get number
          ...?
          // done using file, close it
          ifs.close();
      }
  }
  </code></pre>
  
  <p>How would I do this? Also, am I handling the file open correctly in terms of successful open? </p>
  
  <p>Thanks.</p>