|
I am sorry, but not clear with your requirement. Anyway, this is what I understand so far:
If there is a 4-character field in your file, and you want to extract it, you can use this:
nRet = fscanf(fp, "%4d", &myInt);
if ( nRet == 0 )
{
nRet = fscanf(fp, "%4s", &myStr);
if ( nRet == 0 )
TRACE("Cannot extract this field\n");
}
|
|
|
|
|
your question is not very clear - does the file have two numbers, say
3425
876
?
If so, you can reformat them using the CString::Format(...) function and rewrite them back to the file.
ashish
|
|
|
|
|
no.. here what the file has
hello, hi, 5s%4d%4d
and i have to convert %4d -> number ( eg. 342)
|
|
|
|
|
I pretty much have no knowledge of MFC's other than the few tutorials I read here. Anyway, would the program below be simple to convert into a GUI? I tried to create a dialog based application to no avail.
------------------------
// Inventory System
/*
LOGIN/PW:
admin/admin
power/power
end/end
*/
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
vector<string> vitem;
vector<int> vquantity;
void arecord() {
string name;
int quantity = 0;
cout << endl;
cout << "Enter item name: ";
cin >> name;
cout << "Enter quantity: ";
cin >> quantity;
vitem.push_back(name);
vquantity.push_back(quantity);
}
void dblist() {
cout << endl;
cout << "-----------------------------------------------" << endl;
for (int i=0; i < vitem.size(); i++) {
cout << i << " : " << vitem[i] << " " << vquantity[i] << endl;
}
cout << "-----------------------------------------------" << endl;
}
void drecord() {
int rnumber = 0;
cout << endl;
cout << "What record do you wish to delete: ";
cin >> rnumber;
vitem.erase(vitem.begin() + rnumber);
vquantity.erase(vquantity.begin() + rnumber);
}
void erecord() {
int rnumber = 0;
int nquantity = 0;
vector<string>::iterator n = vitem.begin();
vector<int>::iterator a = vquantity.begin();
string nname;
cout << endl;
cout << "Which record do you wish to modify: ";
cin >> rnumber;
cout << "What will be the new item name: ";
cin >> nname;
cout << "What will be the new quantity: ";
cin >> nquantity;
n[rnumber] = nname;
a[rnumber] = nquantity;
}
void srecord() {
string tsearch;
cout << endl;
cout << "What item do you wish to search for: ";
cin >> tsearch;
for (int i = 0; i < vitem.size(); i++) {
if (vitem[i] == tsearch) {
cout << endl;
cout << i << " : " << vitem[i] << " " << vquantity[i] << endl;
}
}
}
void power() {
int option = 0;
while (option != 4) {
cout << endl;
cout << "USER: POWER" << endl;
cout << "1) Add records." << endl;
cout << "2) List records." << endl;
cout << "3) Search records." << endl;
cout << "4) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, 3, or 4: ";
cin >> option;
if (option == 1)
arecord();
else if (option == 2)
dblist();
else if (option ==3)
srecord();
}
}
void end() {
int option = 0;
while (option != 3) {
cout << endl;
cout << "USER: END" << endl;
cout << "1) List records." << endl;
cout << "2) Search records." << endl;
cout << "3) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, or 3: ";
cin >> option;
if (option == 1)
dblist();
else if (option == 2)
srecord();
}
}
void admin() {
int option = 0;
while (option != 6) {
cout << endl;
cout << "USER: ADMIN" << endl;
cout << "1) Add records." << endl;
cout << "2) List records." << endl;
cout << "3) Delete records." << endl;
cout << "4) Edit records." << endl;
cout << "5) Search records." << endl;
cout << "6) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, 3, 4, 5, or 6: ";
cin >> option;
if (option == 1)
arecord();
else if (option == 2)
dblist();
else if (option ==3)
drecord();
else if (option == 4)
erecord();
else if (option == 5)
srecord();
}
}
int loginpw() {
string login;
string pw;
cout << endl;
cout << "Enter Login: ";
cin >> login;
cout << "Enter Password: ";
cin >> pw;
if (login == "power") {
if (pw == "power")
power();
else
cout << "Wrong password!" << endl;
return -1;
}
else if (login == "end") {
if (pw == "end")
end();
else
cout << "Wrong password!" << endl;
return -1;
}
else if (login == "admin") {
if (pw == "admin")
admin();
else
cout << "Wrong password!" << endl;
return -1;
}
else {
cout << "Invalid login!" << endl;
return -1;
}
}
int load() {
string litem;
int lquantity;
ifstream fin("is.txt");
if (!fin)
return 0;
while (false == fin.eof()) {
fin >> litem >> lquantity;
vitem.push_back(litem);
vquantity.push_back(lquantity);
}
vitem.pop_back();
fin.close();
}
void save() {
ofstream fout("is.txt");
for (int i = 0; i < vitem.size(); i++)
fout << vitem[i] << " " << vquantity[i] << endl;
fout.close();
}
int main() {
load();
loginpw();
save();
return 0;
}
|
|
|
|
|
at first look .. very simple
put a button / menu option for each of the options in the main code and write a handler that does whatever it should do
cant see a problem here myself
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" sonork: 100.18128 8028finder.com
|
|
|
|
|
Thanks for replying. Is a handler the equivalent of int main() in C++?
|
|
|
|
|
I think your main problem is that cout writes to stdout, and there is no stdout in windows. THere are ways to redirect the stdout to a window, you may want to search for that here on CP.
Also, the paradigms between a GUI and a console app are different, therefore you may have to restructure how you want your program to look in a dialog. Maybe it would make more sense to have different fields that are filled with data, rather than having one large text display.
Other than that you should have no problem porting the logic between the two programs.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanks for the reply. The paradigm of Windows programming is what really gets me confused. Although the program I posted above is procedural, I do have a pretty good understanding of OOP but this MFC stuff just goes right over my head. Do you recommend any beginner's books?
|
|
|
|
|
Charles Petzold's books on Win programming are a worthy read.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Will look into it, thanks.
|
|
|
|
|
Chson wrote:
Do you recommend any beginner's books?
A good start is also the Scribble tutorial that comes with MSDN. Give it a try!
Best regards,
Alexandru Savescu
|
|
|
|
|
I've set up a class in my project that is based on the CTreeCtrl class and am trying to handle messages in the class. It will handle some, but for messages like WM_RBUTTONUP or WM_LBUTTONUP, for example, it doesn't handle those messages when the action is performed on one of the Tree items. They only work if you execute the action in the blank area of the control. Any thoughts on why this is the case and how I can get it to handle these messages?
|
|
|
|
|
Stew wrote:
They only work if you execute the action in the blank area of the control.
Probably tree control enters into modal loop when you click on items and move the mouse a little bit. In such case, messages are processed internally by routine deep inside comctl32 - you'll be unable to process them without hook.
You should handle NM_CLICK and NM_RCLICK instead.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
CListCtrl
What message is passed about when the little box is being drawn to select a group of items? Or is there a message that I can respond to when a new item is selected as part of a group of items being selected in such a fashion.
Thanks!
Dugs
|
|
|
|
|
Check LVN_ITEMCHANGING and LVN_ITEMCHANGED.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
|
|
Hi,
I created a setup using the a setup project in Visual C++ .NET Standard, which works absolutely fine on the dev box, but when I try a vanilla install of Windows 2000 it complains saying it needs the .NET framework installed.
Surely MS Installer 2.0 doesn't need the .NET framework?!
Any help very gratefully received.
TIA.
Paul.
|
|
|
|
|
PaulMdx wrote:
Surely MS Installer 2.0 doesn't need the .NET framework?!
Maybe not, but perhaps your program does!
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Hi Nish,
Thanks for the reply.
Nope, that's not it. We also tried adding the .NET framework MSM, which didn't do anything.
The setup complains before the program is even installed (when the setup.exe is first clicked on).
Paul.
|
|
|
|
|
Hmmm.
This is a wild guess, okay! But in most installers we can set the option to check for some bare minimums. For example you can set the minimum requirements to Windows 98 or say you can insist on IE 5.5 etc...
Maybe somewhere in your installation settings you have enabled the .NET runtime requirement. Thus the installer sees that the runtime is not installed and it stops!
If this was a stupid guess, please forgive me. I am just making a long shot in the dark.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
|
As a long time C++ programmer, I find VC++ far superior to Delphi for the kind of work I do.
Delphi is a little too focused on RAD for my way of developing.
Michael
Errata 1: p. 154, section 'Defusing'. For 'red wire' read 'blue wire'.
|
|
|
|
|
choosing either Delphi or Visual C++ depends largely on what you are doing.... although C++ executes faster, Delphi compiles in a single pass which means it will always be faster than MSVC, and most other C/C++ compiler out there.... Delphi is also based on the Pascal language, but borland have their own version, Object Pascal, which supports most features found in C++
if you want to do database programming, or large GUI-based programs (using windows common controls and such), Delphi is by far the best choice. if you plan on creating games or other performance-critical applications, C++ is probably a better choice (i am not saying Delphi is slow in any way here, because it isnt). if you want to learn programming, Delphi is far easier to learn than Visual Basic and outperforms it in just about any circumstance (Delphi executables also dont need a DLL with the runtime libraries in it to run either, but that option can be activated to produce tiny executables....)
I actually have both Visual C++ and Delphi and use them both often - which one you use depends on what you want to do (although i prefer Delphi for it's ease of use....)
in the end, it's up to you....
(sorry for the massive amount of text, but im going through caffeine withdrawal and my brain is going crazy....
-- señor codeman
codeman@crowbartherapy.cjb.net
|
|
|
|
|
East or West NoDoubt.. VC++ is best..
Renjith The True CP ian
|
|
|
|