重载<<操作员ostream

时间:2011-05-24 06:35:06

标签: c++ operator-overloading

为什么以下行不起作用?

#include <iostream>

std::ostream& operator <<( std::ostream& os, const char *c)
{
    os << c; // why does this line doesn't work?
    return os;
}

int main()
{
    const char *c = "Hi";
    std::cout << c;
}

1 个答案:

答案 0 :(得分:5)

问题是std::ostream& operator <<( std::ostream& os, const char *c)已在iostream中重载。