Note that there are some explanatory texts on larger screens.

plurals
  1. POReading input from fstream
    text
    copied!<p>So it is a simple problem. Simply read input from a specific file. Use the input as a Celsius temperature and convert this temperature into Fahrenheit then print the results to the user.</p> <p>The problem seems to occur when I try to save input from the file. Located in the while block. I get an error I know may be caused by trying to use an int value in getline. I am fairly new to c++ and not sure how to do this. I have tried a myriad of ways but none seem to work. Any help would be greatly appreciated!</p> <p>I did <code>#include &lt;fstream&gt;</code>.</p> <p>The file contains these three values '0 50 100'.</p> <p>This is the section of the code I have been working with:</p> <pre><code>//values for the files three input values int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; ifstream inFile; //Input file variable inFile.open("celsius_input.dat"); //open the file if(!inFile){ cout &lt;&lt; "Unable to open file"; exit(1); //terminate with error }//end if while (inFile) { cin.ignore(); getline(inFile, inVal1); getline(inFile, inVal2); getline(inFile, inVal3); // read the files values inFile.close();//Close file } //end while farenheit1 = (9.0/5.0) * inVal1 + 32.0; //formula farenheit2 = (9.0/5.0) * inVal2 + 32.0; //formula farenheit3 = (9.0/5.0) * inVal3 + 32.0; //formula cout &lt;&lt; "The first Inputed Value, " &lt;&lt; inVal1 &lt;&lt; " degrees, Converted Into Farenheit Is " &lt;&lt; farenheit1 &lt;&lt; " Degrees!" &lt;&lt; endl; //output of results cout &lt;&lt; " " &lt;&lt; endl; cout &lt;&lt; "The Second Inputed Value, " &lt;&lt; inVal2 &lt;&lt; " degrees, Converted Into Farenheit Is " &lt;&lt; farenheit2 &lt;&lt; " Degrees!" &lt;&lt; endl; //output of results cout &lt;&lt; " " &lt;&lt; endl; cout &lt;&lt; "Teh Third Inputed Value, " &lt;&lt; inVal3 &lt;&lt; " degrees, Converted Into Farenheit Is " &lt;&lt; farenheit3 &lt;&lt; " Degrees!" &lt;&lt; endl; //output of results cout &lt;&lt; " " &lt;&lt; endl; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload