How to convert vector iterator to int in C++

You need to use standard function std::distance index = std::distance( myvector.begin(), it ); if ( index < myvector.size() ) { // do something with the vector element with that index } Try always to use std::distance even with random access iterators. This function is available in the new and old C++ Standards.

Direction of two points

Answer 1: it is Vector(x2-x1,y2-y1) Answer 2: Normalizing means to scale the vector so that its length is 1. It is a useful operation in many computations, for example, normal vectors should be specified normalized for lighting calculations in computer graphics. The normalized vector of v(x,y) is vn(x/Length(v), y/length(v)). HTH

c++ stl what does base() do

base() converts a reverse iterator into the corresponding forward iterator. However, despite its simplicity, this correspondence is not as trivial as one might thing. When a reverse iterator points at one element, it dereferences the previous one, so the element it physically points to and the element it logically points to are different. In the … Read more

C++ vector literals, or something like them

In C++0x you will be able to use your desired syntax: vector<vector<vector<string> > > vvvs = { { {“x”,”y”, … }, … }, … }; But in today’s C++ you are limited to using boost.assign which lets you do: vector<string> vs1; vs1 += “x”, “y”, …; vector<string> vs2; … vector<vector<string> > vvs1; vvs1 += vs1, … Read more

small string optimization for vector?

Boost 1.58 was just released and it’s Container library has a small_vector class based on the LLVM SmallVector. There is also a static_vector which cannot grow beyond the initially given size. Both containers are header-only. facebook’s folly library also has some awesome containers. It has a small_vector which can be configured with a template parameter … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)