佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 806|回复: 2

vc++ file 的问题

[复制链接]
发表于 11-7-2006 11:19 PM | 显示全部楼层 |阅读模式
如果要checking ....
我的file 是否已经create了,source code应该怎样写??

if(file(member.dat)==NULL) ??


还有。。。要怎样做number 和alphabet validation?
可多多指教。。。
谢谢
回复

使用道具 举报


ADVERTISEMENT

发表于 12-7-2006 04:11 PM | 显示全部楼层
原帖由 bye_bye 于 11-7-2006 11:19 PM 发表
如果要checking ....
我的file 是否已经create了,source code应该怎样写??

if(file(member.dat)==NULL) ??

可多多指教。。。
谢谢

你可以先尝试去读取该文件,如果失败就代表文件不在那里。

  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;

  4. int main(){
  5.         ifstream fin("filepath",ios::in);
  6.         if(!fin){
  7.                 cout<<"File not found!\n";
  8.         }
  9.         return 0;
  10. }
复制代码
回复

使用道具 举报

 楼主| 发表于 12-7-2006 10:40 PM | 显示全部楼层
大哥大姐。。帮帮忙。。


void main()
{
userInterface theUserInterface; //<---- interface class
Rent rent;                         //<--- rent class

void password();
fstream file;
   
     
  ifstream check("rent.dat");
        if(c!heck) {
        rent.setDefault();  << ----- 为什么这个function不会走? >< 如果我没有用if ,setdefault ()就会跑。。为什么??
        }
                password();



theUserInterface.interact();



//========================================================



void Rent::setDefault()
{
        Rent RentADD;
        fstream file; //Describe File datatype
        file.open("rent.dat",ios::app); //To append data to file

        for(int j=1; j<13; j++)
  {
          RentADD.setunitno(j);
          
  for (int i=0; i<12; i++) {
           RentADD.setFee(i,0);
                                    }
  file.write((char*)&RentADD,sizeof(RentADD));
        }
         
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-9-2024 07:33 AM , Processed in 0.100489 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表