C++;矢量错误(Visual C+;+;2008快速版) 我试图在 Visual C++ 2008 Express版< /C> >:中运行这个小程序 #include <vector> int main(){ vector<bool> features(4,false); for(vector<bool>::iterator i = features.begin(); i != features.end(); i++){ cout<<features[i]; } }

C++;矢量错误(Visual C+;+;2008快速版) 我试图在 Visual C++ 2008 Express版< /C> >:中运行这个小程序 #include <vector> int main(){ vector<bool> features(4,false); for(vector<bool>::iterator i = features.begin(); i != features.end(); i++){ cout<<features[i]; } },c++,vector,compiler-errors,C++,Vector,Compiler Errors,除了相同的错误消息框之外 编辑(2) 在添加#include并使用std::cout后,我得到以下结果: 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 p

除了相同的错误消息框之外

编辑(2)

在添加
#include
并使用
std::cout
后,我得到以下结果:

   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>------ 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 ==========
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 ==========
1>----构建已启动:项目:SFS,配置:调试Win32------
1> 编译。。。
1> SFS.cpp
1> .\SFS.cpp(1):警告C4627:“#include”:在查找预编译头使用时跳过
1> 将指令添加到“stdafx.h”或重新生成预编译头
1> .\SFS.cpp(2):警告C4627:“#include”:在查找预编译头使用时跳过
1> 将指令添加到“stdafx.h”或重新生成预编译头
1> .\SFS.cpp(16):致命错误C1010:查找预编译头时出现意外的文件结尾。您是否忘记在源代码中添加“#include”stdafx.h”?
1> 生成日志保存在“文件://c:\Users\Ola\Documents\Visual Studio 2008\Projects\SFS\SFS\Debug\BuildLog.htm”
1> SFS-1个错误,2个警告
======生成:0成功,1失败,0最新,0跳过==========
除了相同的错误消息框之外

为什么呢?我怎样才能解决这个问题


谢谢。

奇怪的MSV东西。您包含的第一个文件是“stdafx.h”?应该是

另外,执行清理生成(重建或清理/生成)

#包括“stdafx.h”
#包括
int main(){
向量特征(4,假);
for(vector::iterator i=features.begin();i!=features.end();i++){

我可能不知道答案,但这对我来说很有效

#include <iostream>
#include <vector>

int main(){
    std::vector<bool> features(4,false);
    for(std::vector<bool>::iterator i = features.begin(); i != features.end(); i++){
        std::cout<< (*i);
    }
}
#包括
#包括
int main(){
std::向量特征(4,假);
for(std::vector::iterator i=features.begin();i!=features.end();i++){

std::cout试试这样的方法:

#include "stdafx.h"

#include <vector>
#include <iostream>

using namespace std;

int main()
{
    vector<bool> features(4,false);
    for(vector<bool>::iterator i = features.begin(); i != features.end(); i++)
    {
        cout << *i;
    }
}
#包括“stdafx.h”
#包括
#包括
使用名称空间std;
int main()
{
向量特征(4,假);
for(vector::iterator i=features.begin();i!=features.end();i++)
{

我遇到了同样的问题。我用

#include <vector> 
所有的错误都消失了


我想知道为什么?最后,当我定义二维向量时,我用了:<代码> STD::向量Myvector;<代码>:STD::向量Myvector;如果未指定<代码> STD命名空间。

错误预编译头。请在你的项目中关闭它们,并重新考虑我的POS。ted代码是SFS.cpp的完整内容,我会添加“#include”并将“cout”替换为“std::cout”。请参阅编辑后的答案。另外,请不要对问题进行重大更改。对于不同的问题,请使用不同的答案。@PoweRoy。如何关闭预编译标题?Thanks@Med-您在Visual Studio中创建的项目的类型是什么?请尝试添加空项目。如何关闭使用p生成的选项是否在项目属性中重新编译标题?Thanks@Med-如果不需要,只需包含stdafx.h即可
#include "stdafx.h"

#include <vector>
#include <iostream>

using namespace std;

int main()
{
    vector<bool> features(4,false);
    for(vector<bool>::iterator i = features.begin(); i != features.end(); i++)
    {
        cout << *i;
    }
}
#include <vector> 
using namespace std;