为 vector 重载 << (输出操作符)

来源:互联网 发布:阿里云 画图 工具 编辑:程序博客网 时间:2024/05/22 07:07

代码如下:

#include <iostream>#include <vector>using namespace std;ostream& operator<< (ostream& out, vector<string>& _vec);int main() {        vector<string> vec(10, "n");        cout << vec << endl;}ostream& operator<< (ostream& out, vector<string>& _vec) {        vector<string>::const_iterator it = _vec.begin();        for(; it != _vec.end(); ++it)                out << *it;        return out;}~  
卒。

0 0
原创粉丝点击