我想确认这是否是 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 header 。
最佳答案
我的第一个猜测是您忘记包含 header (可能是 <string>
)。您最终可能会从不同的 header 得到一些最小的前向声明(或类似的东西),让部分代码可以编译,但其他部分会以奇怪的方式中断,从而导致误导性错误消息。
在快速测试中,它使用 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());
}
关于c++ - 对 vector os 字符串进行排序 c++ visual studio 2010 - 错误 C2784 无法推断模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13631842/