How to print out the contents of a vector?

后端 未结 19 1192
旧时难觅i
旧时难觅i 2020-11-22 03:46

I want to print out the contents of a vector in C++, here is what I have:

#include 
#include 
#include 
#include         


        
19条回答
  •  忘了有多久
    2020-11-22 04:21

    overload operator<<:

    template
    OutStream& operator<< (OutStream& out, const vector& v)
    {
        for (auto const& tmp : v)
            out << tmp << " ";
        out << endl;
        return out;
    }
    

    Usage:

    vector  test {1,2,3};
    wcout << test; // or any output stream
    

提交回复
热议问题