For a beginning c++ class I need to input a file with different celcius temperatures and have the program convert those into fahrenheit and output them as a .txt file. Im having trouble making the calculations out of the input values. Heres what I have so far.
else if(mainmenu=1)
{
cout << "Celcius to Fahrenheit Program Initiated." <<endl;
ifstream cfile("celcius.txt"); //declare the input file
while(! cfile.eof()) //until end of file
{
getline(cfile,line); // get the values
int line;
cout << line*9.0/5.0+32<<endl; // calculate the conversion
ofstream offile("Barnett_Fahrenheit_Output.txt"); // define output file
offile << line*9.0/5.0+32<<endl; // output converted values to file
}
when I to to convert the string into int I keep getting line=0 which makes the entire function = 32. Does anybody know how I can take these values out of the string and be able to convert them?
this is just a section of my code.
line is defined earlier on as a string so the getline function will work on it. I thought that if i redefined it as an integer then it would be able to compute but thats not working. how do I convert from string to integer using stoi or atoi?