I didn't even know that function existed. It certainly looks cleaner than my way. =)
That function certainly does exist. In fact, if you look in any of the standard header files, you should find that it is used quite frequently for the purpose you are describing. An portion of <iostream>:
Code:
#ifndef _IOSTREAM_
#define _IOSTREAM_
#include <istream>
#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
_STD_BEGIN
// OBJECTS
static ios_base::Init _Ios_init;
extern _CRTIMP istream cin;
extern _CRTIMP ostream cout;
extern _CRTIMP ostream cerr, clog;
// CLASS _Winit
class _CRTIMP _Winit {
public:
_Winit();
~_Winit();
private:
static int _Init_cnt;
};
// WIDE OBJECTS
static _Winit _Wios_init;
extern _CRTIMP wistream wcin;
extern _CRTIMP wostream wcout, wcerr, wclog;
_STD_END
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */
#endif /* _IOSTREAM_ */