Converting Celcius to Fahrenheit from String

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?
Is this your exact code?

Doesn't look like it would compile to me. Why is line declared after it's passed into the getline function?

Also, check the condition of your else-if statement. Is that syntax really what you want?

Finally, if you want to perform arithmetic on strings, you'd need to convert them using stoi or atoi or something like that.
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?
You can't have two variables in the same scope with the same identifier.

Here's how to use atoi, with a brief example: http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/

stoi will require a C++11 compliant compiler. Here's how to use it if your compiler will let you: http://en.cppreference.com/w/cpp/string/basic_string/stol
stoi worked like a charm. thank you so much.
Topic archived. No new replies allowed.