(English is not my native language; please excuse typing and grammar errors.)
I'm trying to create a vector<int>
object with known length n
.
I knew that I could do this by vector<int> v(n);
or vector<int> v = vector<int>(n);
. However, when I tried to do it by vector<int> v = n;
, I got an Compile Error.
In my previous experience, vector<int> v = n
seems the same as vector<int> v = vector<int>(n)
, but it proves that I'm wrong.
I've read the cpp reference and searched "C++ vector initialize with an integer" on stackoverflow but cannot find much useful information.
So what's the difference between the three ways? Thanks in advance.