제가 읽은 책을 뒤적여 보니까 내용이 나오는 군요..
열혈강의 C++ 프로그래밍입니다. 지금은 절판된... (참고로 새로운 출판사에서 개정판이 나왔습니다. 열혈 C++ 라는 이름으로..)
윤성우씨 책 10-5 절에 보면 cout, cin, endl 의 비밀 이라는 이름으로 설명합니다.
그러니까 cout 은 ostream 클래스의 인스턴스 입니다. 이름공간 std 에서 선언한...
cin 은 istream 클래스의 인스턴스 이구요... 그러니까
#include < iostream >
을 넣어주죠, 그 헤더파일에서 인스턴스 선언이 이루어진 것 같아요... 이름공간 std 에서,
그렇기 때문에 std::cout, std::cin 이렇게 사용하는 것이구요...
음 그렇기 때문에 >> << 연산자의 오버로딩도 가능하군요...
자세한 것은 더 찾아보세요...
Thanks for being one of those who care for people and mankind.
I'd like to be one of those as well.
선언은 iostream에 다음과 같이 선언되어 있습니다.
namespace std
{
...
extern istream cin;
extern ostream cout;
...
}
C++ standard(는 아니고 draft지만)에는 다음과 같이 main body 실행전에 (ios_base::Init()이 호출되는 동안) 생성/초기화 되고, program 실행 중에는 소멸되지 않습니다.
(Chapter 27.3 Standard iostream objects in Working draft, Standard for Programming Language C++)
The objects are constructed, and the associations are established at some time prior to or during first time an object of class ios_base::Init is constructed, and in any case before the body of main begins execution. The objects are not destroyed during program execution.
cin, cout은 전역 변수이고 컴파일러마다 다르겠지만 main전의 stuff code에서 생성되는 군요
애초에 c++개발자가 cout대신 사용자가 직접 만들어서 쓰게 하는게 조금 번거롭겠지만 명확하지 않았나 하는 생각이 듭니다
ostream MyOut;
MyOut << "abcde";
제가 읽은 책을 뒤적여 보니까 내용이 나오는
제가 읽은 책을 뒤적여 보니까 내용이 나오는 군요..
열혈강의 C++ 프로그래밍입니다. 지금은 절판된... (참고로 새로운 출판사에서 개정판이 나왔습니다. 열혈 C++ 라는 이름으로..)
윤성우씨 책 10-5 절에 보면 cout, cin, endl 의 비밀 이라는 이름으로 설명합니다.
그러니까 cout 은 ostream 클래스의 인스턴스 입니다. 이름공간 std 에서 선언한...
cin 은 istream 클래스의 인스턴스 이구요... 그러니까
#include < iostream >
을 넣어주죠, 그 헤더파일에서 인스턴스 선언이 이루어진 것 같아요... 이름공간 std 에서,
그렇기 때문에 std::cout, std::cin 이렇게 사용하는 것이구요...
음 그렇기 때문에 >> << 연산자의 오버로딩도 가능하군요...
자세한 것은 더 찾아보세요...
Thanks for being one of those who care for people and mankind.
I'd like to be one of those as well.
위에 첨언하면
선언은 iostream에 다음과 같이 선언되어 있습니다.
namespace std
{
...
extern istream cin;
extern ostream cout;
...
}
C++ standard(는 아니고 draft지만)에는 다음과 같이 main body 실행전에 (ios_base::Init()이 호출되는 동안) 생성/초기화 되고, program 실행 중에는 소멸되지 않습니다.
(Chapter 27.3 Standard iostream objects in Working draft, Standard for Programming Language C++)
The objects are constructed, and the associations are established at some time prior to or during first time an object of class ios_base::Init is constructed, and in any case before the body of main begins execution. The objects are not destroyed during program execution.
예 감사합니다
cin, cout은 전역 변수이고 컴파일러마다 다르겠지만 main전의 stuff code에서 생성되는 군요
애초에 c++개발자가 cout대신 사용자가 직접 만들어서 쓰게 하는게 조금 번거롭겠지만 명확하지 않았나 하는 생각이 듭니다
ostream MyOut;
MyOut << "abcde";
댓글 달기