Skip to main content
improved formatting
Source Link
Captain Obvlious
  • 20.2k
  • 5
  • 50
  • 83
//values for the files three input values
int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0,
    farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1
    << " degrees, Converted Into Farenheit Is "
    << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2
    << " degrees, Converted Into Farenheit Is "
    << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3
    << " degrees, Converted Into Farenheit  Is "
    << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; 
int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; 
//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 << "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 << "The first Inputed Value, " << inVal1
    << " degrees, Converted Into Farenheit Is "
    << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2
    << " degrees, Converted Into Farenheit Is "
    << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3
    << " degrees, Converted Into Farenheit  Is "
    << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl;
deleted 11 characters in body
Source Link
David G
  • 97.6k
  • 41
  • 173
  • 258

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.

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!

I did #include <fstream>.

The file contains these three values '0 50 100'.

This is the section of the code I have been working with:

`intint i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; `         

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.

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!

I did #include <fstream>.

The file contains these three values '0 50 100'.

This is the section of the code I have been working with:

`int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; `         

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.

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!

I did #include <fstream>.

The file contains these three values '0 50 100'.

This is the section of the code I have been working with:

int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; 
added 2 characters in body; edited title
Source Link
Mat
  • 207.9k
  • 41
  • 407
  • 422

c++ Reading input from fstream

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.

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!

I did '#include fstream'#include <fstream>.

The file contains these three values '0 50 100'.

This is the section of the code I have been working with:

`int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; `         

c++ Reading input from fstream

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.

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!

I did '#include fstream'.

The file contains these three values '0 50 100'.

This is the section of the code I have been working with:

`int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; `         

Reading input from fstream

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.

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!

I did #include <fstream>.

The file contains these three values '0 50 100'.

This is the section of the code I have been working with:

`int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0, farenheit1 = 0, farenheit2 =0,farenheit3 = 0; //values for the files three input values
 
 ifstream inFile; //Input file variable


inFile.open("celsius_input.dat"); //open the file

if(!inFile){
     cout << "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 << "The first Inputed Value, " << inVal1 << " degrees, Converted Into Farenheit Is " << farenheit1 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "The Second Inputed Value, " << inVal2 << " degrees, Converted Into Farenheit Is " << farenheit2 << " Degrees!" << endl; //output of results
cout << "     " << endl;

cout << "Teh Third Inputed Value, " << inVal3 << " degrees, Converted Into Farenheit  Is " << farenheit3 << " Degrees!" << endl; //output of results
cout << "     " << endl; `         
Source Link
Loading