来自fstream的ostream

来自fstream的ostream

本文介绍了来自fstream的ostream_iterator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! std :: ostream_iterator可以从ostream而不是fstream构建。 如果使用out模式打开fstream,我怎样才能获得ostream_iterator? 我没有使用指向任何基类的指针。 Fraser。a std::ostream_iterator can be constructed from a ostream but not a fstream.If the fstream is opened with the out mode how can I get a ostream_iterator?I am not using a pointer to any base class.Fraser.推荐答案 fstream派生自ostream,因此你可以从 一个fstream。 你有一些不能正常使用的代码吗? johnfstream derives from ostream, so you can construct an ostream_iterator froman fstream.Do you have some code where it''s not working?john 本来有助于包含那些提供这些错误信息的代码。 以下编译即使在在古老的VC ++ 6中,它还可以在Comeau C ++上编译 。 #include< iostream> #include< fstream> #include< iterator> #include< algorithm> using namespace std; int main(int argc,char ** argv) { fstream file(" some_file.txt"); const char msg [] =" something or other" ;; copy(msg,msg + strlen(msg),ostream_iterator< char>(file,"")) ; } 正如我所说,这应该有效,所以要么你有一个duff编译器,一个实时STL 实现或者你在代码中犯了错误。 johnWould have helped to include that code that gives those error messages.The following compiles for me even on the ancient VC++ 6, it also compileson Comeau C++.#include <iostream>#include <fstream>#include <iterator>#include <algorithm>using namespace std;int main(int argc, char** argv){fstream file("some_file.txt");const char msg[] = "something or other";copy(msg, msg + strlen(msg), ostream_iterator<char>(file, ""));}As I said this should work, so either you have a duff compiler, a duff STLimplementation or you''ve made a mistake in your code.john 这篇关于来自fstream的ostream_iterator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 08:46