我一直使用MinGW或Dev-C++在Microsoft Windows上使用C++編寫代碼,但現在必須使用代碼塊。 我已經下載並使用標準程序進行安裝。CodeBlocks HelloWorld C示例不工作:未聲明錯誤「ptrdiff_t」
我試圖運行supersimple HelloWorld.cpp示例文件,但我得到了很多編譯錯誤:
#include <iostream>
using namespace std;
int main()
{
cout << 「Hello World!」 << endl;
}
這裏是我的編譯器錯誤的列表:
Compiling: C:\Temp7\provaC\test00.cpp
In file included from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cstring:49,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/mingw32/bits/c++locale.h:42,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/iosfwd:46,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/ios:44,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/ostream:45,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/iostream:45,
from C:\Temp7\provaC\test00.cpp:1:
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cstddef:52: error: `::ptrdiff_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cstddef:53: error: `::size_t' has not been declared
In file included from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cstring:51,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/mingw32/bits/c++locale.h:42,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/iosfwd:46,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/ios:44,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/ostream:45,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/iostream:45,
from C:\Temp7\provaC\test00.cpp:1:
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:36: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:37: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:38: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:39: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:40: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:46: error: expected constructor, destructor, or type conversion before "strcspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:46: error: expected `,' or `;' before "strcspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:49: error: expected constructor, destructor, or type conversion before "strlen"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:49: error: expected `,' or `;' before "strlen"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:50: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:51: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:52: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:55: error: expected constructor, destructor, or type conversion before "strspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:55: error: expected `,' or `;' before "strspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:58: error: expected constructor, destructor, or type conversion before "strxfrm"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:58: error: expected `,' or `;' before "strxfrm"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:65: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:66: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:72: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:73: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:77: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:80: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:81: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:90: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:91: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:100: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:102: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:104: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:109: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:125: error: expected constructor, destructor, or type conversion before "wcscspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:125: error: expected `,' or `;' before "wcscspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:127: error: expected constructor, destructor, or type conversion before "wcslen"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:127: error: expected `,' or `;' before "wcslen"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:128: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:129: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:130: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:133: error: expected constructor, destructor, or type conversion before "wcsspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:133: error: expected `,' or `;' before "wcsspn"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:136: error: expected constructor, destructor, or type conversion before "wcsxfrm"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:136: error: expected `,' or `;' before "wcsxfrm"
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:150: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:151: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:157: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:158: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:175: error: `size_t' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/string.h:176: error: `size_t' has not been declared
In file included from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/mingw32/bits/c++locale.h:42,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/iosfwd:46,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/ios:44,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/ostream:45,
from C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/iostream:45,
from C:\Temp7\provaC\test00.cpp:1:
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cstring:89: error: `::strxfrm' has not been declared
C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cstring:90: error: `::strcspn' has not been declared
Process terminated with status 1 (0 minutes, 5 seconds)
看來,在標準庫中,某些結構不存在(ptr_diff_t
,size_t
等)。
有人可以幫我,讓我編譯我簡單的HelloWorld.cpp?
謝謝!
必要的包括你的程序是''和''。 –
@Kerrek SB,請參閱http://www.cplusplus.com/reference/iostream/;我相信你通常不需要將istream或ostream直接包含在內,因爲它們都被iostream覆蓋。我不知道問題出在哪裏,因爲Eclipse和MinGW可以很好地工作。我猜這是一個配置問題。你能得到用於編譯的命令行,並從命令提示符嘗試它嗎? – cosimo193
@ cosimo193:該網站是可憎的。不過,我認爲你(不知不覺)正確地認爲C++ 11 *要求''包含''; C++ 03沒有這樣說。 –