c++ - 对 vector os 字符串进行排序 c++ visual studio 2010 - 错误 C2784 无法推断模板参数

标签 c++ visual-studio-2010

我想确认这是否是 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/

相关文章:

c++ - 让 Stringstream 从字符串中的字符 A 读取到 B

c# - 未调用 WH_KEYBOARD_LL Hook

c# - 定义具有 1 个以上原型(prototype)的函数

c++ - 麻省理工学院球体模拟设置中的 Matlab 错误

visual-studio-2010 - 表示UML中的一对多关系

c++ - 我的项目在 vs2008 中编译没有任何问题,但在 2010 中却没有?

c++ - std::vector 默认构造函数可以抛出异常吗

c++ linux accept()在套接字关闭后阻塞

visual-studio - Visual Studio 2010 - 将第一个项目添加到解决方案后看不到解决方案名称/根

正在释放的 C++ 指针未分配错误