File just wont get created.
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 79 80 81 82 83 84 85 86 87 88
|
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstring>
#define MAXIMUMPOWER 10000
using namespace std;
int main()
{
char *p = new char[MAXIMUMPOWER + 1];
int *cost = new int;
int rec = sizeof(p) + sizeof(int);
int *n = new int;
char *check = new char[1 + 1];
bool input = false;
fstream fout("D:\\Program Files\\BunchOiTems.txt", ios::binary|ios::in|ios::out);
while(true)
{
cout << "Any new items? (Y for Yes N for No) " << endl;
cin.getline(check, 2);
if(check[0] == 'Y' || check[0] == 'y')
input = true;
else
input = false;
while(input == true)
{
cout << "Input record number: " << endl;
cin >> *n;
cout << "Input name of an item(0 = exit): " << endl;
cin.getline(p, MAXIMUMPOWER);
cin.getline(p, MAXIMUMPOWER);
if(strlen(p) == 0)
{
input = false;
break;
}
cout << "Input cost of an item(0 e exit): " << endl;
cin >> *cost;
if(*cost == 0)
{
input = false;
break;
}
fout.seekp(*n * rec);
fout.write(reinterpret_cast<char*>(cost), sizeof(int));
fout.write(p, sizeof(char));
fout.close();
}
cout << " Input a record number of an given Item: " << endl;
cin >> *n;
fout.seekp(*n * rec);
fout.read(reinterpret_cast<char*>(cost), sizeof(int));
fout.read(p, sizeof(char));
cout << "NAME: " << p << endl;
cout << "COST: " << *cost << endl;
fout.close();
}
delete [] p;
delete [] check;
delete cost;
delete n;
fout.close();
system("PAUSE");
return 0;
}
|
Topic archived. No new replies allowed.