以下代码是我为自己编写的代码,用于测试指针和向量如何工作。这个带有向量的简单代码有什么问题?
我对C++非常陌生。
#include <vector>
#include <iostream>
using namespace std;
int main(void)
{
//Create the integer pointer vector, and clean it to initialize
vector<int *> lol;
lol.clear();
//Create the pointers and point them to 1,2,3
int a1=1, a2=2, a3=3;
int* a, b, c;
a=&a1;
b=&a2;
c=&a3;
//Put the pointers into the vector
lol.push_back(a);
lol.push_back(b);
lol.push_back(c);
//Return the value of the middle pointer
cout << *lol[1];
}
我在编译时遇到了一大堆错误。
任何人都可以帮忙吗?请记住,我只能了解新手。
您不需要在声明后立即清除。 –
请记住将来发布完整的错误文本。 – chris