C++ 中使用vector来存储数据,其打开方式是什么?
开始第一步,定义一个vector类型的变量,try 一try。
#include <iostream>
#include <utility>
// #include <vector> /*先注释,编译器会报什么错误?*/
using namespace std;
typedef unsigned int uint32;int main(void)
{std::vector<uint32> vec_u32;cout<<vec_u32[0]<<endl;return 0;}
执行编译命令, 报错, 如下所示:
root@localhost:/home/root/testWorkSpace/CPP11/vector/main.cpp: In function ‘int main()’:
/export01/home/lki8szh/testWorkSpace/CPP11/vector/main.cpp:32:10: error: ‘vector’ is not a member of ‘std’std::vector<uint32> vec_u32;^~~~~~
取消注释“// #include ”
执行编译命令,OK。使用vector类需要先引用其头文件。
root@localhost:/home/root/testWorkSpace/CPP11/vector$ cmake --build ./build
Scanning dependencies of target move
[ 50%] Building CXX object CMakeFiles/move.dir/main.cpp.o
[100%] Linking CXX executable move
[100%] Built target move
运行该命令,出现了segement fault 。怎么回事?
root@localhost:/home/root/testWorkSpace/CPP11/vector$ ./build/move
Segmentation fault (core dumped)