如何重载 << 运算符以使其从流中读取?
How can I overload the << operator to make it read from a stream?
可能重复:
操作员过载
要重载>>的问题<运算符,让它们从流中读/写?
有人能解释一下如何做到这一点吗?
定义
std::ostream &operator<<(std::ostream &out, Foo const &x)
{
// write a representation of x to out
// you can use << on x's members
return out;
}
std::istream &operator>>(std::istream &in, Foo &x)
{
// read a representation of a Foo from in
// and use it to modify x
return in;
}
适当地。
您不是只定义operator >>
或operator <<
吗?
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 如何使用Luacneneneba API正确读取字符串和表参数
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- C++将文本文件中的数据读取到结构数组中
- 正在将csv文件读取为双精度矢量
- 呼叫运营商<<临时
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 为什么在读取文件大小时文件IO速度会发生变化
- 正在读取二进制文件(is_open)
- 如何在c++中从文本文件中逐行读取整数
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 独立读取-修改-写入顺序
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组