C언어 심화, C++/Struct

Cin /Cout / Operator Overloading

Soongle 2019. 6. 12. 20:33

cin, coutC++의 Standard Stream Object이다.

cinistream 클래스의 객체이고

coutostream 클래스의 객체이다.


template<class _Elem, class _Traits> inline
basic_ostream<_Elem, _traits)&__CLRCALL_OR_CDECL endl(basic_ostream<_Elem, _Traits>& _Ostr)
{
    _Ostr.put(_Ostr.widen('\n'));
    _Ostr.flush();
    return (_Ostr);
}

coutendl'\n' 이후 flush()연산을 통해 버퍼를 비워준다.

때문에 '\n'을 사용할 때 보다 속도가 느리다.


cout으로 구조체 출력하기

ostream& operator << (ostream& os, const Struct& st)
{
  os<<st.member1<<" "<<st.member2;
  return os;
}