写程序,尤其是调试的时候,会想着直接输出一个map或者vector来调错。
但本来的cout<<没有这种功能。我们就会想了,要是c++能和python一样,直接输出一个列表(vector)或者dict(map),那有多好。
翻翻书可以知道,cout<<的<<也是重载出来的,那我们就再重载一下,来实现自己的功能呗。
老样子,先放成品
#include<bits/stdc++.h>
using namespace std;
namespace py_pr{
template<typename T>
inline ostream& out_put(ostream& o,const T & x){
return o<<x;
}
inline ostream& out_put(ostream& o,const string& x){
return o<<"\""<<x<<"\"";
}
inline ostream& out_put(ostream& o,const char* & x){
return o<<"\""<<x<<"\"";
}
inline ostream& out_put(ostream& o,const char & x){
return o<<"\'"<<x<<"\'";
}
template<typename T1,typename T2>
inline ostream& out_put(ostream& o,const pair<T1,T2> & x){
out_put(o,x.first);