C Primer中第8章关于流的一道习题,帮忙看一下
时间:2008-05-26 11:10:12
来源:论坛整理 作者: 编辑:chinaitzhe
这个是我写的程序:
#include <iostream>
#include <string>
using namespace std;
istream& ReadInput(istream& state)
{
string temp;
while(state>>temp, !state.eof())
cout < <temp;
state.clear();
return state;
}
int main()
{
istream _state = ReadInput(cin);
return 0;
}
编译时出现错误:
c:\program files\microsoft visual studio 9.0\vc\include\istream(846) : error C2248: 'std::basic_ios <_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios <_Elem,_Traits>'
这个是什么意思?
假如在main()函数中调用的时候直接调用就没有错误,为什么啊?
#include <iostream>
#include <string>
using namespace std;
istream& ReadInput(istream& state)
{
string temp;
while(state>>temp, !state.eof())
cout < <temp;
state.clear();
return state;
}
int main()
{
ReadInput(cin); //这里直接调用就可以。
return 0;
}
还有,我这个程序对不对啊?符不符合题目的要求啊?
网友回复:istream& _state = ReadInput(cin);
网友回复:没有错误阿
网友回复:
能不能解释一下啊?
返回值是引用的函数就得这样调用吗?
网友回复:你不写&那么就会产生一个新的istream的对象.
但是这个对象是不答应拷贝的,所以得使用引用
关键字:Primer,章流,一道,习题,帮忙,
上一篇:关于读取某路径下文件的问题
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面