std::find on std::vector< std::string > 在 Visual C++ 2008 中无法编译?
std::find on std::vector< std::string > does not compile in Visual C++ 2008?
我在Visual C 2008 Express Edition上尝试了此代码,但没有编译:
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
typedef std::string Element;
typedef std::vector< Element > Vector;
typedef Vector::iterator Iterator;
Vector v;
std::find( v.begin(), v.end(), std::string( "xxx" ) );
return 0;
}
我有以下错误:
c:programmimicrosoft visual studio 9.0vcincludealgorithm(40) : error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
GCC校正了相同的代码,并按照预期的方式进行编译。
它是Visual Studio的错误吗?我该如何使我的示例在Visual C 2008上工作?
您忘记了#include <string>
。
您必须始终包含代码所需的所有标题。切勿依靠有时碰巧起作用的魔术递归包含物。对于您在代码中使用的所有内容,您必须知道已声明的位置,并保证在翻译单元中可见声明。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- std::find on std::vector< std::string > 在 Visual C++ 2008 中无法编译?
- visual studio 2008中不能包含std头文件
- Boost lexical_cast<std::string>(int) MSVC 2008 bug
- 避免内联显式实例化的 std::vector<T> 代码?(Visual Studio C++ 2008)
- C++ std::begin(c) for vs 2008
- 如何在std::map中插入项目而不违反MISRA C++2008必需规则5-2-12
- visual studio 2008 sp1 std::string::c_str() err
- 为什么visual express 2008不能自动完成std::系统
- std::使用Visual C++2008映射未声明的标识符