^.^
I am making a program but I can't continue because there's something wrong...
Expand|Select|Wrap|Line Numbers
- #include<iostream>
- #include<string>
- #include<fstream>
- using namespace std;
- struct record{
- int IdentificationNumber;
- string Name;
- int Quantity;
- double Cost;
- };
- main(){
- record TheTool;
- fstream file("hardware.dat", ios::in|ios::out|ios::binary);
- if(!file){
- cerr<<"File could not be opened or created"<<endl;
- exit(1);
- }
- cout<<"I Will Add Something To The File"<<endl;
- cout<<"Enter tool ID Number: ";
- cin>>TheTool.IdentificationNumber;
- cout<<"Enter tool name: ";
- cin.ignore();
- getline(cin, TheTool.Name);
- cout<<"Enter Quantity: ";
- cin>>TheTool.Quantity;
- cout<<"Enter Cost: ";
- cin>>TheTool.Cost;
- file.seekp((TheTool.IdentificationNumber-1)*sizeof(record));
- file.write(reinterpret_cast<const char *> (&TheTool), sizeof(record));
- file.close();
- fstream file1("hardware.dat", ios::in|ios::out|ios::binary);
- file1.seekg(0);
- file1.read(reinterpret_cast<char*>(&TheTool),sizeof(record));
- while(file1.good()){
- cout<<TheTool.IdentificationNumber<<TheTool.Name<<TheTool.Quantity<<TheTool.Cost<<endl;
- file1.read(reinterpret_cast<char*>(&TheTool),sizeof(record));
- }
- }
(Sorry for the wrong grammar and not nice explanation, i'm not good in english hehe.. thank you!)