Is std :: vector :: begin () from previous C ++ 11 equivalent to std :: vector :: data () in C ++ 11?
Depends on what you mean by equivalent. Selecting will get a reference to the first element in the vector, but the iterator returned by begin () cannot be converted to the type of pointer returned by data ().
The reason why I ask for this, before C ++ 11, I used to treat std :: vector :: begin () as a pointer, but after C ++ 11 this is not the case, and I can not drop the pointer equivalent .
Your code worked with good (or bad) luck, depending on how you look at it.
So, can I use data () instead of C ++ 11?
There are two pairs of iterators that share vector data:
begin() to end()
and
data() to data() + size()
you can use either in any standard algorithm, and the result will be the same.
In a good style, you should use begin() to end() where you can (which will almost always be).
source share