繁体   English   中英

将fstream作为参数传递

[英]passing fstream as argument

我无法将fstream作为参数传递给函数

就像fname(fstream , char []); /* Prototype */ fname(fstream , char []); /* Prototype */

并调用fname(fs, p);

它引发错误,

In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/include/c++/4.8/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
     ios_base(const ios_base&);

后来我知道我必须使用fstream& 我只是想知道流与对象之间的区别吗? 如果是的话,有人可以告诉一些适当的阅读来源,以免我再搞砸了。 非常感谢。

正如错误所说

error: 'std::ios_base::ios_base(const std::ios_base&)' is private ios_base(const ios_base&);

fstream没有副本构造函数(该副本构造函数定义为私有)。 您需要按reference而不是按value传递fstream对象。

这实际上意味着您的原型签名需要更改

fname(fstream& , char []);

流对象不可复制。 在与文件关联的复制流中应该发生什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM