I do not like using namespace std
, but I am also tired of having to type std::
in front of every cout
, cin
, cerr
and endl
. So, I thought of giving them shorter new names like this:
// STLWrapper.h
#include <iostream>
#include <string>
extern std::ostream& Cout;
extern std::ostream& Cerr;
extern std::istream& Cin;
extern std::string& Endl;
// STLWrapper.cpp
#include "STLWrapper.h"
std::ostream& Cout = std::cout;
std::ostream& Cerr = std::cerr;
std::istream& Cerr = std::cin;
std::string _EndlStr("
");
std::string& Endl = _EndlStr;
This works. But, are there any problems in the above which I am missing? Is there a better way to achieve the same?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…