Works for me. Even compiles using g++ -Wall -Wextra with no warnings, so on that.
One issue I do have is that the program cannot handle input for a full name. e.g. Bill works fine, but Bill Smith causes the program to loop indefinitely. You may wan to fix that. One suggestion would be to use getline() rather that std::cin.
Thanks for your feedback. I am running it using vs-code and it is compiled without any issue. If I run it for the first time I pressed 1, then I entered 100 (Account number), Mark (Name) and 200 (Balance). Then, I pressed 3 to see the table that works fine (I can see all information for this account on the table):
A/c no. NAME Balance
100 Mark 200
Then I pressed 2 to add a deposit and I entered 350. Now I expect this value is added to the previous balance (200) and the new balance should be 550 now. However, after pressing 3, I still see the above table and the balance has not been updated. Do you know where the problem could be?
In the deposit_amount function you should break out of the loop after updating the record. So change it to:
while(File.read((char *) &ac, (int)sizeof(ac)))
cout<<"\n\nEnter The amount to be deposited: ";
int pos = -1 * (int)sizeof(ac);
cout<<"\n\n\t Record Updated";
break; // ***do not need to read any further records
In the display_all function change the while statement to:
while(!inFile.read((char *) &ac, sizeof(ac)).eof()) // break if end of file
You are welcome. But, as k5054 suggested, there are a few areas that cpuld be tidied up. For example I would read all accounts into memory at the beginning of the program, and only write out new or updated entries. That way you will always have the most up to date information available.
As you're using C++, you might consider using a std::map for the internal data structure. e.g std::map<int, account>. If you do that, then you can access an account via its account number, without searching for it
std::map<int, account> accounts;
accounts[account_no].dep(amount); // add amount to an account;
within worker thread, could a pointer to CDialog access its member variables or even functions, nothing to do with its UI elements, without using postmessage or sendmessage?. I expect the answer is YES.
I'm not sure what the difference is in your mind. std::cout and std::format (C++ 20) aren't really API's in my mind. They're fine for a simple utility (think ping or netstat), writing log files or doing data I/O, but quickly become unweildly when trying to do full screen I/O like menus, dialogs, pop-ups etc. If you're pursuing the latter, then you probably want to use a library that handles all the screen painting for you, managing overlays, pull down menus, etc. You might want to look at this page to see if any of them meet your needs C++ Library TUI libraries | LibHunt
You can probably find other examples googling for C++ TUI libraries.
The libraries that get fancy tended to rely on stuff that I couldn't be sure existed or at least would existed in the future.
Not to mention that a console app should be pretty simple in the first place. If you need complex user interactions then a console app probably isn't the way.
If I didn't want a normal UI then I would be more likely to control it via either command line options and/or configuration files. Actually I have been doing just those for years without any need for anything else.
Maybe there's a simpler way to do this. Or a good tutorial ?
I have a time string formatted like this (with spaces): "07 h 08 min 51 s"
According to the documentation, should the format string should be "%H h %M min %S s" ?
And if I understand how this should work, I should be able to do something like that, no?
Is there something I am missing ? or just the documentation too obtuse ?
const std::string time("07 h 08 min 51 s");
const std::string format("%H h %M min %S s");
iss >> std::chrono::parse(format, tp);
Your time string doesn't fully specify a time point. You can change it to:
iss >> std::chrono::parse (format, d);
and d is correctly calculated as 25731, which represents your time converted to seconds.
In the docs the key point is:
If from_stream fails to parse everything specified by the format string, or if insufficient information is parsed to specify a complete result, or if parsing discloses contradictory information, is.setstate(std::ios_base::failbit) is called.