1. 程式人生 > >C編譯錯誤,執行錯誤以及常見問題。

C編譯錯誤,執行錯誤以及常見問題。

1.  在原始碼中遺失“;” 
偵錯程式錯誤資訊:syntax error : missing ';' 
2.  缺少名稱空間使用定義:即缺少“using namespace std;” 偵錯程式錯誤資訊:例:error C2065: 'cout' : undeclared identifier 例如cout/cin/endl/<</>>等在名稱空間中定義的符號和標示符無法使用。 3.  變數未定義就直接使用 
偵錯程式錯誤資訊:例:error C2065: 'i' : undeclared identifier        C++語言中,變數的使用必需遵循先宣告定義,後使用的原則。 4.  在程式中使用中文標示符,如將英文”;”錯誤輸入成了”;” 偵錯程式錯誤資訊:error C2018: unknown character '0xa3' 
在C++中,除程式註釋可以採用中文外,其餘字元要求使用英文。不少同學在建立工程或程式名稱時也使用中文名稱,建議改掉這種習慣。 
5.  在使用輸入輸出流的時候錯誤使用了標示符“>>”“<<”,例cout>>a; 偵錯程式錯誤資訊:例:error C2676: binary '>>' : 'class 
std::basic_ostream<char,structstd::char_traits<char>>' does not define this operator or a conversion to a type acceptable to the predefined operator 
對於流操作的方向搞錯是一個普遍錯誤,問題本來並不複雜,可能是由於沒有認真看書的原因。 
6.定義的變數型別與使用不對應,如宣告為float,但實際給與了一個double的值,例: 
    require.async(['wkcommon:widget/ui/lib/sio/sio.js'], function(sio) { var url = 'https://cpro.baidustatic.com/cpro/ui/c.js'; sio.callByBrowser( url, function () { BAIDU_CLB_fillSlotAsync('u2845605','cpro_u2845605'); } ); }); 

float pi=3.412345245656245; 
偵錯程式錯誤資訊:warning C4305: 'initializing' : truncation from 'const double' to 'float' 
7.變數在賦值之前就使用,例:int a, b, c; c=a+b; cin>>a>>b; 
    偵錯程式錯誤資訊:warning C4700: local variable 'a' used without having been initialized