还是ostringstream?
istringstream a("asd");
istringstream b = a; // This does not work.我猜memcpy也不会起作用。
发布于 2009-09-29 01:29:00
istringstream a("asd");
istringstream b(a.str());编辑:根据您对其他回复的评论,听起来您可能还想将fstream的全部内容复制到strinstream中。您也不想/必须一次只处理一个字符(而且您是对的--这通常很慢)。
// create fstream to read from
std::ifstream input("whatever");
// create stringstream to read the data into
std::istringstream buffer;
// read the whole fstream into the stringstream:
buffer << input.rdbuf();发布于 2009-09-29 01:20:35
你不能仅仅复制数据流,你必须使用迭代器来复制它们的缓冲区。例如:
#include <sstream>
#include <algorithm>
......
std::stringstream first, second;
.....
std::istreambuf_iterator<char> begf(first), endf;
std::ostreambuf_iterator<char> begs(second);
std::copy(begf, endf, begs);https://stackoverflow.com/questions/1490100
复制相似问题