Convert vector to vector ( elegant way )

后端 未结 3 2135
旧巷少年郎
旧巷少年郎 2021-02-13 14:46

I would like to know if there is an elegant way or a built-in function to convert vector to vector. What I\'ve done is simp

3条回答
  •  我寻月下人不归
    2021-02-13 15:15

    Using copy and ostream_iterator:

    #include 
    #include 
    #include 
    #include 
    
    int main()
    {
      std::vector numbers{1.0, 2.1, 3.2};
      std::stringstream output;
      std::copy(numbers.begin(), numbers.end(), std::ostream_iterator(output, " "));
    
      std::cout << output.str() << std::endl;
    }
    

提交回复
热议问题