我正在學習C++,但遇到了一個我不明白的錯誤。Float,Double,Char,C++錯誤。哪裏不對?
這裏是我的源代碼,包含註釋
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
float h; //a float stands for floating point variable and can hold a number that is a fraction. I.E. 8.5
double j; //a double can hold larger fractional numbers. I.E. 8.24525234
char f; // char stands for character and can hold only one character (converts to ASCII, behind scenes).
f = '$'; //char can hold any common symbol, numbers, uppercase, lowerver, and special characters.
h = "8.5";
j = "8.56";
cout << "J: " << j << endl;
cout << "H: " << h <<endl;
cout << "F: " << f << endl;
cin.get();
return 0;
}
編譯時我收到以下錯誤(因爲我學習個人參考。):
錯誤C2440: '=':不能從 轉換「爲const char [4]」到「浮動」 沒有上下文,其中該轉換是可能的
而
錯誤C2440: '=':不能從 轉換 '爲const char [5]' 到 '雙' 沒有上下文中,這種轉換是可能
你們可以指向正確的方向? 我剛剛瞭解到const(20分鐘前可能),我不明白爲什麼以前的程序不能正常工作。
雙引號內的文本是*字符串*,它與數值不同。 – GManNickG 2010-10-31 19:46:27
這個問題是一個簡單的語言問題,任何介紹教程將涵蓋。不要以爲它屬於這裏。 – ideasman42 2012-11-11 10:15:17