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

一个简单读取文件C++有关问题

2012-02-21 
一个简单读取文件C++问题`voidcheck(intid,charpwd[]){Userinfo*uififstreamifileintflag0ifile.open(

一个简单读取文件C++问题`
void   check(int   id   ,   char   pwd[])
{
Userinfo   *uif;
ifstream   ifile;
int   flag=0;
ifile.open( "test.txt ");

if(ifile.fail())
{
              cout < < "不能打开文件 ";
      exit(1);
}
        while(!ifile.eof())              
{
ifile.read((char   *)uif,sizeof(Userinfo));
if   (id==uif-> id)
{
flag=1;
if(!strcmp(pwd,uif-> pwd))
{
cout < < "密码正确 ";
}
else  
{
cout < < "密码不正确 ";
       
}
}

}

不知道错在哪里`

[解决办法]
ifile.open( "test.txt ", ios_base::binary);
[解决办法]
并且,记得写文件的时候也要用binary模式。
[解决办法]
你的文件是二進制數據,就用binary打開,是一般文本,就用文本模式打開。

热点排行