1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <conio.h>
using namespace std;
//enum columns{petName=0, ownerName=1, age=2, weight=3, height=4, yearsOwned=5, gender=6};
int main()
{
fstream dataFile;
fstream binOut;
string theArray[12];
int index = 0;
dataFile.open(".\\DataFiles\\PetInfo.txt",ios::in);
if(dataFile.fail())
{
cout<<"Unable to Process."<<endl;
return 999;
}
binOut.open(".\\Datafiles\\petInfo.bin",ios::out|ios::binary);
if(!binOut.is_open())
{
cout << "\n\nUnable to open the BIN output file.\n\n";
return 98;
}
while(!dataFile.eof())
{
getline(dataFile, theArray[index],'\n');
/*getline(dataFile, theArray[index][ownerName],',');
getline(dataFile, theArray[index][age],',');
getline(dataFile, theArray[index][weight],',');
getline(dataFile, theArray[index][height],',');
getline(dataFile, theArray[index][yearsOwned],',');
getline(dataFile, theArray[index][gender],'\n');*/
binOut.write(reinterpret_cast<char *>(&theArray),sizeof(theArray));
index++;
}
int maxElements=index;
dataFile.close();
binOut.close();
}
|