當試圖將變量acidWeight
放入answerString
時,+操作員不起作用。這是邏輯錯誤還是數據類型錯誤?+由於有條件,操作員不能工作
string byName() {
string acidName;
string answerString;
float acidWeight;
cout << "Give me the name of the acid and I'll give you the weight." << endl;
getline(cin, acidName);
cout << endl << endl;
if (acidName == "valine") {
acidWeight = 117.1469;
}
else {
cout << "This doesn't appear to be valid." << endl;
}
answerString = "The weight of " + acidName + "is " + acidWeight + "per mole";
return answerString;
}
使用['的std :: ostringstream'](http://en.cppreference.com/w/cpp/io/basic_ostringstream)來構建格式化的字符串輸出。 –
「不起作用」是什麼意思?你的意思是「由於有條件而不工作」? – juanchopanza
由於'acidWeight'的數據類型導致了構建錯誤。 – Rocky