0

/* Data was not inserted into the file what is the problem idon't no can any one solve this problem*/

#include<iostream> #include <fstream> using namespace std; typedef struct transaction { char data[100]; char *txnName=data; long amount; char pan[100]; char *PAN=pan; public:void TrDetails() { std::cout<<"Enter Name:"; std::cin>>data; std::cout<<"Enter the amount:"; std::cin>>amount; std::cout<<"Enter the Pan No:"; std::cin>>pan; std::cout<<"Entered Details are:"<<std::endl<<data<<std::endl<<amount<<std::endl<<pan; } }; int main() { transaction TXN_RECORD; TXN_RECORD.TrDetails(); fstream file("Tranx1.dat",ios::app|ios::out|ios::binary); file.open("Tranx1.dat",ios::app|ios::out|ios::binary); file.write((char *)&TXN_RECORD,sizeof(TXN_RECORD)); ofstream of; std::cout<<"Inserted Data Succ"; cin.getline(TXN_RECORD.data, 100); of<<TXN_RECORD.data; file.close(); }

4th Mar 2019, 1:37 PM
M Ashok Kumar
M Ashok Kumar - avatar
1 Antwort
0
There's a lot for me to comment on here so I rewrote some and explained things at GitHub.com/JayTheLabAide/CPlusPlus/blob/master/structFileIO.cpp
5th Mar 2019, 9:39 AM
Sparrow Elle
Sparrow Elle - avatar