2
IO 연산자 오버로드와 관련된 일부 C++ 코드를 테스트하고 있습니다. 코드로 다음과C++에서 입출력 연산자를 오버로드 할 때 cout/cin을 사용합니까?
class Student {
private:
int no;
public:
Student(int n)
{
this->no = n;
}
int getNo() const {
return this->no;
}
friend istream& operator>>(istream& is, Student& s);
friend ostream& operator<<(ostream& os, const Student& s);
};
ostream& operator<<(ostream& os, const Student& s){
cout << s.getNo(); // use cout instead of os
return os;
}
istream& operator>>(istream& is, Student& s)
{
cin >> s.no; // use cin instead of is
return is;
}
을 그러나 <<
및 >>
내부 I 사용할 수
ostream& operator<<(ostream& os, const Student& s){
os << s.getNo(); // use os instead of cout
return os;
}
istream& operator>>(istream& is, Student& s)
{
is >> s.no; // use is instead of cin
return is;
}
<<
에서, I는 OS 대신 COUT 및 >>
연산자 유사성 객체를 사용. 그래서, 그 차이가 있는지 궁금합니다.
표준 입력/출력 스트림이란 무엇입니까? "실행을 시작할 때 컴퓨터 프로그램과 그 환경 (일반적으로 텍스트 터미널) 사이에 미리 연결된 입출력 채널입니다"(http://en.wikipedia.org/wiki/Standard_streams) ?? – ipkiss
오른쪽에 대한 소리. –
지금은 분명합니다. 고마워. – ipkiss