我正在尝试在以下位置运行这个小程序Visual C++ 2008 Express Edition
:
#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 ==========
我还收到以下错误消息:
编辑(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 ==========
除了同样的错误信息框。
编辑(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 ==========
除了同样的错误信息框。
这是为什么?我该如何解决这个问题?
谢谢。