查看: 803|回复: 2
|
vc++ file 的问题
[复制链接]
|
|
如果要checking ....
我的file 是否已经create了,source code应该怎样写??
if(file(member.dat)==NULL) ??
还有。。。要怎样做number 和alphabet validation?
可多多指教。。。
谢谢 |
|
|
|
|
|
|
|
发表于 12-7-2006 04:11 PM
|
显示全部楼层
原帖由 bye_bye 于 11-7-2006 11:19 PM 发表
如果要checking ....
我的file 是否已经create了,source code应该怎样写??
if(file(member.dat)==NULL) ??
可多多指教。。。
谢谢
你可以先尝试去读取该文件,如果失败就代表文件不在那里。
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main(){
- ifstream fin("filepath",ios::in);
- if(!fin){
- cout<<"File not found!\n";
- }
- return 0;
- }
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 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));
}
} |
|
|
|
|
|
|
| |
本周最热论坛帖子
|