【发布时间】:2016-08-15 19:55:19
【问题描述】:
我不可能找到以下行为的解释:
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/stream.hpp>
#include <iostream>
#include <sstream>
TEST_CASE(rdbuf) {
{
boost::iostreams::stream<boost::iostreams::file_sink> file("test");
file << "Hello, World!";
}
{
boost::iostreams::stream<boost::iostreams::file_source> file("test");
std::string line;
std::getline(file, line);
CHECK_EQUAL(line, "Hello, World!");
}
{
boost::iostreams::stream<boost::iostreams::file_source> file("test");
std::istringstream iss;
std::string line;
file.rdbuf(iss.rdbuf());
std::getline(file, line);
CHECK_EQUAL(line, "");
std::getline(iss, line);
CHECK_EQUAL(line, ""); // (1) Why?
}
{
boost::iostreams::stream<boost::iostreams::file_source> file("test");
std::ostringstream oss;
std::string line;
file.rdbuf(oss.rdbuf());
std::getline(file, line);
CHECK_EQUAL(line, "");
line = oss.str();
CHECK_EQUAL(line, ""); // (2) Why?
}
}
在(1) 和(2) 这两种情况下,我都比较期待
CHECK_EQUAL(line, "Hello, World!");
成功。
我在这里实际上想念什么?谢谢。
【问题讨论】:
标签: c++ boost iostream io-redirection boost-iostreams