Use std::to_string
to convert the integer to string.
regex goal( "^((?:\\w+ ){" + std::to_string(index) + "})\\w+" );
By the way, the _Ptr
member of vector<T>::iterator
you keep accessing all over is implementation specific and makes your code unportable. You should use the vector::data
member function instead.
Also, you can avoid all the additional backslashes by using raw string literals.
regex goal( R"reg(^((?:\w+ ){)reg" + std::to_string(index) + R"reg(})\w+)reg" );