所以我已經設置任務++創建在C溫度轉換器使用這個公式:程序總是返回二進制「>>」:沒有運營商發現這需要類型的錯誤左手操作數
Celsius = (5/9)*(Fahrenheit – 32)
到目前爲止我已經想出這個(我已經削減了10日線的價值從一開始就意見,以便發佈的代碼開始於第11行,如果讓任何意義)
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
float celsius;
float farenheit;
std::cout << "**************************" << endl;
std::cout << "*4001COMP-Lab5-Question 1*" << endl;
std::cout << "**************************" << endl << endl;
std::cout << "Please enter a temperature in farenheit: ";
std::cin >> farenheit >> endl;
std::cout << "Temperature (farenheit): " << endl;
std::cout << "Temperature (celsius): " << celsius << endl;
std::cin.get();
return 0;
}
每次我嘗試運行這個程序我收到一個錯誤,每次出現這個錯誤:
1> m:\ visual studio 2010 \ projects \ week 5 \ week 5 \ main.cpp(26):error C2678:binary'>>':找不到操作符,它需要一個類型的左操作數「的std :: basic_istream < _Elem,_Traits>」(或沒有可接受的轉換)
我用盡了一切我能想到的擺脫這種錯誤,但它再次出現每次,任何關於如何想法解決這個問題?
是cin之後必需的endl嗎? (sry,我的C++技能現在被粉碎了......) –
爲什麼'std :: cout'和'using namespace std;'?請一個或另一個。 – john
可以使用std :: endl,唯一的區別是std :: endl會刷新輸出緩衝區,'\ n'不會。如果您不希望頻繁刷新緩衝區,請使用'\ n'。如果你這樣做(例如,如果你想獲得所有的輸出,並且程序不穩定)。 –