0

この小さなプログラムを で実行しようとしています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 ==========

同じエラー メッセージ ボックスに加えて。

何故ですか?どうすればこれを解決できますか?

ありがとう。

4

4 に答える 4

1

奇妙な MSVS のもの。最初に含めるファイルは"stdafx.h"ですか? そのはず。

また、クリーン ビルド (リビルドまたはクリーン/ビルド) を実行します。

#include "stdafx.h"
#include <vector>
int main(){
vector<bool> features(4,false);
for(vector<bool>::iterator i = features.begin(); i != features.end(); i++){
cout<<features[i];
}
}

または、プロジェクト プロパティでプリコンパイル済みヘッダーを使用してビルドするオプションをオフにすることもできます。

以下も必要です。

#include <vector>

vectorと置き換えstd::vectorます。

于 2012-06-23T15:39:08.353 に答える
0

答えはわからないかもしれませんが、これでうまくいきます。

#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);
    }
}
于 2012-06-23T16:06:08.333 に答える
0

私は同じ問題に遭遇しました。使った

#include <vector> 

またstd::vector、ではなくvector、問題はまだそこにあります。後で、次の行を追加しようとしました。

using namespace std;

すべてのエラーがなくなりました!

なぜだろう?最後に、2 次元ベクトルを定義したときに、名前空間が指定されていない場合はstd::vector<vector<double>> myVector;: を使用したことがわかりました。std::vector<std::vector<double>> myvector;std

于 2014-03-15T17:52:58.477 に答える
0

次のようなことを試してください:

#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;
    }
}

VS2010 では、プロジェクト プロパティの C/C++ サブセクション、プリコンパイラ サブセクションでプリコンパイル済みヘッダーをオフにすることができます。

于 2012-06-23T16:10:41.983 に答える