2015-12-20 90 views
-3

我已經創建了一個小系統進行分配。請任何人都可以指導我如何將數據發送到輸出文件/數據庫文件。我需要保存記錄,然後根據需要進行編輯和刪除。因此我需要將數據發送到某個數據庫文件。請幫忙C++,發送數據到輸出文件

#include <iostream> 
#include <string> 
#include <cstring> 
#include <fstream> 
#include <iomanip> 
#include <windows.h> 
#include <sstream> 
#include <algorithm> 
#include <conio.h> 
#include <stdio.h> 
#include <cstdlib> 
#include <iomanip> 
#include <dos.h> 
using namespace std; 
string userName; 
string passWord; 
string selection; 
int option; 

struct patientinfo { 
    string PatientFname; 
    string PatientLname; 
    int Age; 
    int ContactNo; 
    string TreatmentType; 
    string AppDate; 
    string AppTime; 
    int eReciptId; 
}; 

int num; 
patientinfo emp[50]; 
ofstream outputFile("ST.txt"); 

int main() 
{ 

int i=num; 
num+=1; 

cout<< endl << endl << endl << endl << endl << endl 
<< setw(65)<<"|Booking|" << endl << endl << endl << endl 
<< setw(30)<<"First Name  : "; 
cin>>emp[i].PatientFname; 
cout<< setw(30)<<"Last Name  : "; 
cin>>emp[i].PatientLname; 
cout<< setw(30)<<"Age    : "; 
cin>>emp[i].Age; 
cout<< setw(30)<<"Contact No  : "; 
cin>>emp[i].ContactNo; 
cout<< setw(30)<<"Appointment Date : " ; 
cin>>emp[i].AppDate; 
cout<< setw(30)<<"Appointment Time : "; 
cin>>emp[i].AppTime; 
}; 
+0

所以你到目前爲止嘗試過什麼? – Altoyyr

+0

試圖發送outputFile作爲流。沒有工作。 – ceranda

+0

'num'是未初始化的,因此'i'具有不確定的值。 UB。你應該得到一個錯誤/警告。 – LogicStuff

回答

0

猜測你在扭動時必須使用特定的格式,以便你能夠讀回它。每個病人之間可能會有逗號。例如

 if (outputFile.is_open()) 
     { 
      for(int x=0; x<50; i++ 
      { 
      outputFile << emp[i].PatientFname << "," <<emp[i].PatientLname << "," << emp[i].Age <<"\n"; 
    } 
     outputFile.close(); 
     } 

,那麼你可以用ifstream的打開它。每條線都是病人,然後逗號分隔可以給你每個病人的屬性