[問題] 小型提款機
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
字串沒有如預期一般寫入檔案
餵入的資料(Input):
先以new建立帳號
帳號輸入aa
預期的正確結果(Expected Output):
理應出現psw的輸入訊息
錯誤結果(Wrong Output):
error
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<fstream>
//紀錄型態
/*
帳號
型態(管理者、使用者)
密碼
金額
利率
*/
using namespace std;
int user(){
ifstream ip;
ofstream op;
int con=1;
int result;
char ina[100],inp[100];
char ac[100],str[100];
ip.open("data.txt");
op.open("data.txt");
//標頭
begin:
cout<<"account:(enter new to create)";
cin>>ac;
if(strcmp(ac,"new")!=0){
while(con==1)
{
ip >> str;
if(strcmp(str,ac)==0 )
{
result =1;
cout <<"OK!";
break;
}
else if(strcmp(str,ac)!=0 && ~ip.eof())
{
result =2;
break;
}
}
}
else if(strcmp(ac,"new")==0)
{
cout<<"plese enter your new account:";
cin >> ina;
op << ina << ' ';
cout<<"please enter your new psd:";
cin >> inp;
op << inp << ' ';
goto begin;
}
if(result==1)
{
cout<<"ok";
}
else
{
cout<<"error";
goto begin;
}
}
補充說明(Supplement):
這是我認為有錯的副函數
完整沒貼上來
麻煩各位了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.114.220.123
→
03/21 23:34, , 1F
03/21 23:34, 1F
→
03/21 23:41, , 2F
03/21 23:41, 2F
噓
03/21 23:54, , 3F
03/21 23:54, 3F
→
03/21 23:57, , 4F
03/21 23:57, 4F
→
03/21 23:57, , 5F
03/21 23:57, 5F
→
03/21 23:58, , 6F
03/21 23:58, 6F
→
03/22 01:50, , 7F
03/22 01:50, 7F
推
03/23 19:20, , 8F
03/23 19:20, 8F