title: Main function not outputting the text file lines
body: <p>The following code is supposed to get a text file and read all its lines and print them put on console but although it properly saves the fname, it won't do anything after that. I appreciate if you could let me know what the problem is. </p>
  
  <p>EDIT: To be more accurate, I will eventually want to call a few functions inside the else block but I first need to figure out why my program doesn't get to that point.</p>
  
  <hr>
  
  <pre class="lang-C prettyprint-override"><code>int main()
  {
      string fname = "", line, content;
      ifstream ifs; // input file stream
      string command = "";
      int k;
      cout &lt;&lt; "---- Enter your command and the file name : ";
      while (getline(cin, line)){
          int i = 0;
          for (i = 0; i&lt;line.length(); i++) {
              command += line[i];
              if (line[i] == ' ')
              {
                  break;
              }
          }
          for (int j = i + 1; j&lt;line.length(); j++)
          {
              fname += line[j];
          }
          cout &lt;&lt; command;
      }
  
      if (command == "exit ")
      {
          exit(EXIT_SUCCESS);
      }
      // tries to open the file whose name is in string fname                 
      ifs.open(fname.c_str());
  
      if (ifs.fail()) {
          cerr &lt;&lt; "ERROR: Failed to open file " &lt;&lt; fname &lt;&lt; endl;
          ifs.clear();
      }
      else { //do getline here to read content
          while (getline(ifs, content))
          {
              cout &lt;&lt; "Content " &lt;&lt; k++ &lt;&lt; " : " &lt;&lt; content &lt;&lt; endl;
              //Call functions here later
          }
      }
  
  
      ifs.close(); // always remember to close it                         
  
      cout &lt;&lt; "---- Enter another file and command name : ";
  
  }
  </code></pre>