创建我的第一个向量 [Visual Studio 2013] 时出错
Error with the creating of my first vector [Visual studio 2013]
我正在学习C++编程语言,我的第一个向量遇到了一些问题。如果我按照书中的例子(编程原理和使用C++的实践),这就是一个例子:
vector<int> v = { 5, 7, 9, 4, 6, 8 };
我的编译器在这里说: 错误 1 错误 C2440: "初始化" : 无法从"初始值设定项列表"转换为"矢量" c:\users\pierob\documents\visual studio 2013\projects\learnprogramming\learnprogramming\main.cpp 7 1 learnprogramming
你能帮我吗?我有Visual Studio 2013 express(我使用Visual C++编译器2013年11月CTP)。
错误消息指出Vector
,而不是vector
,因此您实际正在编译的代码看起来很可疑。
使用 Visual Studio 2013 Update 3,以下编译包含 0 个错误:
#include <vector>
int main()
{
std::vector<int> v = { 5, 7, 9, 4, 6, 8 };
}
输出:
1> main.cpp
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
请复制上面的代码并编译它以确保它没有错误。
在 std_lib_facilities.h 头文件的第 99 行(对我来说)是一个显然令人作呕的宏黑客,用于获取一个范围检查的向量,上面写着:
#define vector Vector
我将其更改为:
#define vector vector
和您的代码:
vector<int> v = { 5, 7, 9, 4, 6, 8 };
似乎按预期工作。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 在Visual Studio 2013上使用OpenCV 2.4.10时出错
- 尝试在Visual Studio 2013中使用sqlite3_open进行编译时出错
- 在Visual Studio 2013中读取文件时出错
- 使用 Visual Studio 2013 构建过剩 DLL 时出错
- 将 MFC C++项目从 VS 2008 升级到 2013 时出错
- 创建我的第一个向量 [Visual Studio 2013] 时出错