首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

是不是VC6.0下不识别友元啊解决方法

2012-05-22 
是不是VC6.0下不识别友元啊今天写一个C++的程序,突然发现报错说不能访问类中的private成员,但是我已经把此

是不是VC6.0下不识别友元啊
今天写一个C++的程序,突然发现报错说不能访问类中的private成员,但是我已经把此函数说明程友元了啊!大家看看怎么回事,错误从注解的地方开始
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int MAX_NUM_OF_COURSES=30;
const int MAX_ID_LEN=10;
const int MAX_NAME_LEN=8;
class StudentScores
{
public:
StudentScores(){init=false;}
bool date_is_ok(){return init;}
private:
int scores[MAX_NUM_OF_COURSES],num_of_couress;
char id[MAX_ID_LEN],name[MAX_NAME_LEN+1];
bool init;
friend istream &operator >>(istream &in,StudentScores &x);
friend ostream &operator <<(ostream &out,StudentScores &x);
};
 istream &operator >>(istream &in,StudentScores &x)
 {
if(&in==&cin) cout<<"请输入学号,姓名,选课数以及各门课成绩(以学号为'E'结束):\n";
//in>>setw(11)>>x.id;
//if(in.eof()||x.id[0]=='E')
{
x.init=false;
return in;
}
in>>setw(9)>>x.name;
in>>x.num_of_couress;
if(x.num_of_couress>MAX_NUM_OF_COURSES)
{
x.init=false;
return in;
}
for(int i=0;i<x.num_of_couress;i++)
in>>x.scores[i];
x.init=true;
return in;
 }

 ostream &operator <<(ostream &out,StudentScores &x)
 {
out<<x.id<<' '<<x.name<<' '<<x.num_of_couress;
for(int i=0;i<x.num_of_couress;i++)
out<<' '<<x.scores[i];
return out;
 }
int main()
{
ofstream out_file("D:\\score.txt",ios::out);
if(!out_file)
{
cerr<<"打开文件失败!!!\n";
return -1;
}
StudentScores st;
cin>>st;
while(st.date_is_ok())
{
out_file <<st<<endl;
cin>>st;
}
out_file.close();
return 0;
}

[解决办法]
http://www.cnblogs.com/xinjun/archive/2010/07/19/1780902.html
[解决办法]
来迟了
[解决办法]

探讨

引用:

来迟了


忘了说了,我还是不懂为什么会出现这样,和书上说的明显不一样啊 啊,大家解释一下啊

[解决办法]
#include <iostream.h>
#include <fstream>
#include <iomanip>
//using namespace std;
我记得好像是<iostream.h>,并且using namespace std;得注释掉的,当年做的时候,书上好像是这样说的,


[解决办法]
不要用6.0了吧,装个级别高点的呗
[解决办法]
vc6对友元模版支持不行。

热点排行
Bad Request.