来自 std::vector <double>的未格式化流输入
unformatted stream input from std::vector<double>
我正在使用boost::iostream lib来包装到gnuplot的posix管道。为了将二进制内联数据发送到gnuplot,我目前正在做类似于的事情
std::vector<double> d = test_data();
Gnuplot plt; //custom gnuplot class derived from boost::iostream::stream
plt << "plot '-' binary format='%double' notitlen"
plt.write( (char*)( &c.front() ), sizeof(double)*c.size() ); // send binary data
它是有效的,但我想去掉.write,并使用迭代器接口来允许例如std::list作为源。我知道std::ostreambuf_editor允许无格式的输入,但简单地使用std::copy显然不起作用。
这里有一个简单的包装器模板来写出范围:
#include <memory>
#include <iterator>
template <typename FwdIter>
write_range(Gnuplot & gp, FwdIter it, FwdIter end)
{
typedef typename std::iterator_traits<FwdIter>::value_type type;
for ( ; it != end; ++it)
{
gp.write(reinterpret_cast<char const *>(std::addressof(*it)), sizeof(type));
}
}
用法:write_range(gp, mylist.begin(), mylist.end());
相关文章:
- 从格式化输入操作中获取读取字符数
- 如何从标准输入中检测格式化输入错误?
- 如何读取和处理格式化的日期,如 01/11/1998、星期日(10000 个输入)C++
- 是否可以使用一行代码从 std::cin 中提取格式化输入
- 在列中格式化输出(用户输入)
- 如何读取时间输入并格式化输出
- 未格式化/格式化的输入
- 如何格式化重载的 c++ 输入运算符
- 在C++中解析格式化的用户输入
- 解析格式化输入时划分单词时出现问题
- 如何使用 getline 和字符串流来解析格式化的日期和时间输入
- std::getline()从流中读取格式化的输入后读取错误的数据
- 来自 std::vector <double>的未格式化流输入
- 使用cin读取格式化输入
- 如何确定未格式化输入函数读取的字符数
- 正在重新格式化输入的带有空格的字符串
- 扫描 读取格式化输入
- c++中字符串的格式化输入
- 在c++中从格式化输入切换到非格式化输入
- 格式化输入 - scanf 的C++版本是什么?