20110327-8.1.2-IO对象不可复制或赋值

1.只有支持复制的元素类型可以存储在vector或其它容器里。

#include "stdafx.h"
#include
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    ofstream out1,out2;
    out1=out2;

    //ofstream print(ofstream);
    //out2=print(out2);
    return 0;
}

===================================================================================

1>------ 已启动生成: 项目: 20110327-iostream, 配置: Debug Win32 ------
1>生成启动时间为 2011-3-27 11:31:17。
1>InitializeBuildStatus:
1>  正在创建“Debug/20110327-iostream.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
1>ClCompile:
1>  所有输出均为最新。
1>  20110327-iostream.cpp
1>c:/program files/microsoft visual studio 10.0/vc/include/ostream(604): error C2249: “std::basic_ios<_Elem,_Traits>::operator =”: 没有到 private 成员(在“std::basic_ios<_Elem,_Traits>”虚拟基中声明)的访问路径
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits
1>          ]
1>          c:/program files/microsoft visual studio 10.0/vc/include/ios(177) : 参见“std::basic_ios<_Elem,_Traits>::operator =”的声明
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits
1>          ]
1>          此诊断出现在编译器生成的函数“std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator =(const std::basic_ostream<_Elem,_Traits> &)”中
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits
1>          ]
1>
1>生成失败。
1>
1>已用时间 00:00:00.90
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

2.形参或返回类型也不能为流类型。如果需要传递或返回IO对象,则必须传递或返回指向该对象的指针或引用:

ofstream &print(ofstream&);//OK:takes a reference,no copy;

while(print(out2)){/*…*/}//OK:pass reference to out2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值