當你在main函數中只寫了兩行代碼:
cout << "C++" << endl;
return 0;
但是當你運行時,發現出現瞭如下錯誤:
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2061: 語法錯誤: 標識符“acosf”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2059: 語法錯誤:“;”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2061: 語法錯誤: 標識符“asinf”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(19): error C2059: 語法錯誤:“;”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2061: 語法錯誤: 標識符“atanf”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2059: 語法錯誤:“;”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2061: 語法錯誤: 標識符“atan2f”
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(20): error C2059: 語法錯誤:“;”
……
fatal error C1003: 錯誤計數超過 100;正在停止編譯
出現這種情況是因爲編譯器將C++文件編譯爲C導致的。
解決方法如下:
1. 如果你的main文件後綴爲C,改爲cpp即可
2. 如果你發現main文件後綴爲cpp,這時可能是你的IDE設置的問題了,屬性管理器>>通用屬性>>C/C++>>高級>>編譯爲,如果編譯爲裏面爲C,改爲默認值即可