Posts

171: ATM system with file handeling and data backup without using classes and oop

  #include < iostream > #include < fstream > #include < iomanip > #define maxlim 20 // The maximum data that will be stored in .txt file is set limit 20 rows using namespace std ; // using std::cout; // using std::cin; // using std::string; // using std::ios; // using std::getline;      // Using these in place of using namespace std will make compiler fast // using std::ws; // using std::endl; // using std::ifstream; // using std::ofstream; // using std::to_string; string acc_in_use ; // When user is authenticated, his account number will be stored in it and this can be used anywhere string data [ maxlim ][ 4 ]; // Whole .txt file data will be stored in this when import_data() is called and this is global. int rows = 0 ;           // rows are calculated and stored in this for later use in for loops in iterating 2D array void import_data () {     data [ maxlim ][ 4 ]; // initializing array in which ...

170: Import data from .txt file into a 2D array

#include < iostream > #include < fstream > #define maxlim 10       // set what should be the maximum number of row you wanna read using namespace std ; int main () {     string arr [ maxlim ][ 4 ];  // initializing array in which we will import data     ifstream file ;                     // it must be ifstream not fstream     file . open ( " myfile.txt " , ios :: app );  // set file name and ios::app will not overwrite file while writing it again     if ( file . fail ())        // if file does not open program will terminate     {         cout << " File opening filed \n " ;         return 1 ;     }     int rows = 0 ;                  // declaring rows     while ( file . eof () == 0 ) ...