1

これが Visual Studio 2010 のバグかどうかを確認したかったのですが、そうである場合、設定を変更できますか? またはどうすればこれを解決できますか?

#include <iostream>
#include <vector>
#include <algorithm>

std::vector<std::string> test;

test.push_back("hello"); test.push_back("ABC");

std::sort(test.begin(), test.end());

これは、 std::string ヘッダーを含めなかったために発生しました。

4

2 に答える 2

4

私の最初の推測は、ヘッダーを含めるのを忘れたことです (おそらく<string>)。コードの一部をコンパイルできるようにする別のヘッダーからの最小限の前方宣言 (またはそのようなもの) で終わる可能性がありますが、他の部分は奇妙な方法で壊れ、誤解を招くエラーメッセージにつながります。

簡単なテストでは、これは VS 2008 ~ 2012 でコンパイルされます。

#include <vector>
#include <string>
#include <algorithm>

int main() {

    std::vector<std::string> test;

    test.push_back("hello");
    test.push_back("ABC");

    std::sort(test.begin(), test.end());
}
于 2012-11-29T18:12:36.740 に答える
0

それはうまくコンパイルされます....

#include "stdafx.h"
#include <string>
#include <vector>
#include <algorithm>

int _tmain(int argc, _TCHAR* argv[])
{
std::vector<std::string> test;

test.push_back("hello");
test.push_back("ABC");

std::sort(test.begin(), test.end());
return 0;
}
于 2012-11-29T18:10:07.813 に答える