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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
void write()
{
char fileNO[4];
char data[3];
int dat;
ifstream infile;
infile.open("data.dat", ios::in);
infile.get(fileNO,4);
infile.ignore(50);
dat = atoi(fileNO);
cout << "File# = " << fileNO << '\n';
infile.close();
cin.get();
float close;
int x;
char line1[100];
char line2[100];
char line3[100];
char line4[100];
char line5[100];
char filename[10];
int random;
ofstream outfile;
cout << "Enter data to be written: \n";
cin.get(line1, 100);
cin.ignore(101,'\n');
cin.get(line2, 100);
cin.ignore(101,'\n');
cin.get(line3, 100);
cin.ignore(101,'\n');
cin.get(line4, 100);
cin.ignore(101,'\n');
cin.get(line5, 100);
cin.ignore(101,'\n');
random = dat + 1;
cout << "writing file# "<< random << '\n';
itoa(random, filename, 20);
outfile.open( filename ,ios::out);
//make sure file is opened
if (outfile)
{
outfile << line1 << endl;
outfile << line2 << endl;
outfile << line3 << endl;
outfile << line4 << endl;
outfile << line5 << endl;
cout << "Write successfull.\n";
outfile.close();
cin.ignore(1000, '\n');
int file;
file = atoi(fileNO) + 1;
ofstream outfile;
outfile.open( "data.dat" ,ios::out);
outfile << file << endl;
cout << "Data file wrtten successfully.\n";
outfile.close();
cin.ignore();
}
else
{
cout << "Error writing file.\n";
cin.get();
cin.get();
}
}
|