我一直在学习面向对象的计算,特别是迭代器和标准模板库等。
我似乎不太明白为什么如果你写
std:vector<int> - //blah, a vector is created.
Run Code Online (Sandbox Code Playgroud)
但是,在某些情况下,您需要编写
#include <vector> //to include vector library
Run Code Online (Sandbox Code Playgroud)
为什么是这样?我们通常编写“使用命名空间 std”的标准库是否已经包含向量库?
当我删除定义文件#include 时,计算机无法识别我的向量变量。
但是,我在某些情况下看到很多人使用了 vector 函数,而没有使用 std::vector 来实际声明它???
std::vector<int>::iterator pos;
std::vector<int>coll;
Run Code Online (Sandbox Code Playgroud)
这是其他人使用的代码,它似乎有效?
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
int main() {
vector<int>::iterator pos;
vector<int>coll;
}
Run Code Online (Sandbox Code Playgroud)
// 这对我有用,但我想了解为什么这个有效而另一个无效。