引用 | 編輯
f81513
2010-12-09 21:31 |
樓主
▼ |
||
x0
剛學c++沒多久老師派了一個作業 是要使用c++建置一個簡易的會員系統 我的程式碼 不知道為什麼新增會員無法新增到檔案裡 拿原本就存在二元檔裡面的帳號密碼登入也沒有辦法 已經困惑了好多天也修改了好久了 但是就是不知道哪裡出錯了 請高手幫忙看一下 萬分感謝 #include <iostream> #include <fstream> using namespace::std; struct memberRecordFormat { char account;//帳號 char password;//密碼 char name;//姓名 char cellPhone;//手機 }; void check (char* id ,memberRecordFormat memberfile ,int &counter )//看是不是檔案裡就有的帳號 { int i ; for ( i = 1 ; i <= counter ; i++ ) { while ( strcmp ( id , memberfile.account ) == 0 )//看這個帳號有沒有重複 { cout << "此帳號已有人使用\n"; cout << "請輸入帳號: "; cin >> id ; cout << endl; } } } int main() { memberRecordFormat memberfile;//新建的資料(檔案裡的) fstream inFile( "file.dat", ios::in | ios:: out | ios::binary );//開檔 while( !inFile )//看有沒有開成功 { cout << "File could not be opened" << endl; system("pause"); exit( 1 ); } int counter = -1; while(!inFile.eof())//讀檔案裡面的資料 { counter++; inFile.read( reinterpret_cast< char * > ( &memberfile ), sizeof( memberRecordFormat ) );//把資料存進檔案中 } inFile.close();//關檔 int first;//選擇第一步 int second;//選擇第二步 char id;//帳號 char pass;//密碼 char nam;//名字 char cell;//手機 cout << "請輸入:\n1.會員登入\n2.加入會員\n"; cin >> first;//輸入選擇 cout << endl; if( first < 1 || first > 2 )//如果沒有選1或2時 { while(first < 1 || first &g .. 訪客只能看到部份內容,免費 加入會員 x0
|