我試圖運行Visual C++ 2008 Express Edition
這個小程序:C++矢量誤差(的Visual C++ 2008年速成版)
#include <vector>
int main(){
vector<bool> features(4,false);
for(vector<bool>::iterator i = features.begin(); i != features.end(); i++){
cout<<features[i];
}
}
當我這樣做,我得到如下:
1>------ Build started: Project: SFS, Configuration: Debug Win32 ------
1>Compiling...
1>SFS.cpp
1>.\SFS.cpp(1) : warning C4627: '#include <vector>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>.\SFS.cpp(14) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Users\Ola\Documents\Visual Studio 2008\Projects\SFS\SFS\Debug\BuildLog.htm"
1>SFS - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我也收到以下錯誤信息:
EDIT(1)
我添加#include "stdafx.h"
後,我得到如下:
1>------ Build started: Project: SFS, Configuration: Debug Win32 ------
1>Compiling...
1>SFS.cpp
1>.\SFS.cpp(5) : error C2065: 'vector' : undeclared identifier
1>.\SFS.cpp(5) : error C2062: type 'bool' unexpected
1>.\SFS.cpp(6) : error C2065: 'vector' : undeclared identifier
1>.\SFS.cpp(6) : error C2062: type 'bool' unexpected
1>.\SFS.cpp(6) : error C2039: 'iterator' : is not a member of '`global namespace''
1>.\SFS.cpp(6) : error C2065: 'i' : undeclared identifier
1>.\SFS.cpp(6) : error C2065: 'features' : undeclared identifier
1>.\SFS.cpp(6) : error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>.\SFS.cpp(6) : error C2065: 'i' : undeclared identifier
1>.\SFS.cpp(6) : error C2143: syntax error : missing ';' before ')'
1>.\SFS.cpp(6) : error C2143: syntax error : missing ';' before ')'
1>.\SFS.cpp(6) : error C2143: syntax error : missing ';' before '{'
1>.\SFS.cpp(7) : error C2065: 'cout' : undeclared identifier
1>.\SFS.cpp(7) : error C2065: 'features' : undeclared identifier
1>.\SFS.cpp(7) : error C2065: 'i' : undeclared identifier
1>Build log was saved at "file://c:\Users\Ola\Documents\Visual Studio 2008\Projects\SFS\SFS\Debug\BuildLog.htm"
1>SFS - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
除了相同的錯誤消息框。
EDIT(2)
我添加#include<iostream>
和使用std::cout
後,我得到如下:
1>------ Build started: Project: SFS, Configuration: Debug Win32 ------
1>Compiling...
1>SFS.cpp
1>.\SFS.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>.\SFS.cpp(2) : warning C4627: '#include <vector>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>.\SFS.cpp(16) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Users\Ola\Documents\Visual Studio 2008\Projects\SFS\SFS\Debug\BuildLog.htm"
1>SFS - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
除了相同的錯誤消息框。
這是爲什麼?我該如何解決這個問題?
謝謝。
錯誤提到了預編譯頭文件。請關閉你的項目並重建 – RvdK
如果我認爲你的發佈代碼是SFS.cpp的compelet內容,我會添加「#include」,並用「std :: cout」替換「cout」。 –
查看編輯答案。另外,請不要對您的問題做出重大修改。向另一個問題詢問另一個問題。 –