使用STL将标量值乘以向量元素

问题描述:

您好我想(乘,添加等)向量通过标量值例如 myv1 * 3 ,我知道我可以做一个函数与forloop,有一种方法这样做使用STL功能?像{Algorithm.h :: transform function}?

Hi I want to (multiply,add,etc) vector by scalar value for example myv1 * 3 , I know I can do a function with a forloop , but is there a way of doing this using STL function? Something like the {Algorithm.h :: transform function }?

是的,使用 std ::转换

std::transform(myv1.begin(), myv1.end(), myv1.begin(),
               std::bind1st(std::multiplies<T>(),3));