Hi all,
I have the following code:
I want the output to be like below:Code:#pragma once #include <iostream> using namespace std; class Bill{ private: int bill; public: setBill(int); int getBill(); } The implement file is as follow: #include "Bill.h" void Bill::setBill(int bill) { (*this.bill) = bill; } int Bill::getBill() { return bill; } I have a bat file call data.bat and inside it has this data: 1234 1890 1470 In my main file: #include "Bill.h" #include <fstream> int main() { int i=0; Bill *bill[2]; ifstream indata; int num; // variable for input value indata.open("data.dat"); // opens the file if(!indata) { // file couldn't be opened cerr << "Error: file could not be opened" << endl; exit(1); } indata >> num; while ( !indata.eof() ) { // keep reading until end-of-file i++; bill[i]=new Bill; cout << "number is " << num; bill[i]->setBill(num); indata.close(); cout << "End-of-file reached.." << endl; for(int n=0; n < 3; n++) { cout << "bill : " <<bill[n]->getBill<< endl; } cin.ignore(); cin.ignore(); return 0; }
bill:1234
bill:1890
bill:1470
However the output I get is :
bill: -842150451
bill: -842150451
bill: -842150451
I would not figure out the problem.Any help is much appreciated.
Thank you.