|
Zac Howland wrote: Unless you have to define your own exception class for an assignment, you should use the standard exception class, or use MFC's CException class.
Or inherits a class from that. It allows you to add more flexibility.
|
|
|
|
|
True ... forgot to mention that as well. However, you rarely need any more information than what those classes already support, and even the other STL exceptions are mostly just blank classes derived from std::exception.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Oh ic. To be honest I wish I could use MFC, but the syllabus covers basic C++ and we have to abide by it for the major part, because I'm still at the lower end of the learning curve
MFC has its own exceptions and they resemble so much the exceptions that I'm used to with VB for example.
hehe... I think that if I decide to become a software engineer and use C++, I'll need more than silicone
Jon
|
|
|
|
|
jon_80 wrote: To be honest I wish I could use MFC
Don't be too sure about that. While MFC does have its advantages in the Windows' world, it is virtually useless outside of it. STL is far more portable.
You keep posting code that should be written with STL classes, but you only use part of STL (mainly cin/cout). Don't be afraid of string, vector, and list (along with the rest of the containers and algorithms).
Coming from a VB background will be tough. Basically, try to forget everything VB does for you, because you won't find much of that in C++ -- most of it you will have to do yourself.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
jon_80 wrote:
<code> {
throw (CSentenceAr);
return false;
}</code>
You must throw an instance of class CSentenceAr, not the class name. Change the throw statement to:
throw CSentenceAr();
You must have a working default constructor for this class.
|
|
|
|
|
Would I be throwing a new instance that way? The idea is to throw back the same instance with the invalid data.
Jon
|
|
|
|
|
Dear all,
I have dialog with two buttons(one is for automatic logon and one is for UI logon).
when the user selects the UI logon the new dialog pops up with prompting username and password ,after user enter this data he clicks ok button to enter.
But when press automatic logon ,i modified code to fill the default username and password (in username and password edit box),after this generate IDOK notification ,So that its logs automatically with out UI.
But what i need is to hide this popup dialog(which prompts for username and password ) which comes when user press the automatic logon button( i tried to hide this window by using showwindow(hwnd,SW_HIDE) in WM_INIT notification (case WM_INITIALISE: ) in dialog procedure ,but this window flashs and disappears,Is their any way to HIDE this without showing this dialog to user when he press automatic logon)
Manjunath S
GESL
Bangalore
|
|
|
|
|
It would be cleaner if you could separate the logic of window creation from the logic of user input validation. This way, when automatical logging in, you only call the validation logic, without creating the window.
I assume that you know the difference between instantiating a C++ window object and actually creating a window. If not, I'll explain more.
Best,
Jun
|
|
|
|
|
Quickes way: Setup the dialog fields in OnInitDialog() and then call OnOk or OnBnClickedOk() ...it's a quick thing but i don't like it verry much.
A better way is to process the login info in a method not depending on UI. Just pass the login fields as params to your method. In this method, display the dialog if you need to (ie: your user did not check the autologin option or something). The best thing about this is that you can call the same method in your UI validation procedure afterwards.
|
|
|
|
|
The program is executing but it's crashing at the end with the above error.
Code:
#include <iostream>
#include <string.h>
using namespace std;
char* passwordEntry(int allowedSize)
{
const int size = 100;
if (allowedSize > size)
{
cout << "Password size is too large. Size limit is " << size << endl;
allowedSize = size;
}
char password[size];
cout << "Enter your password:";
cin.getline(password,size);
if (strlen(password)>allowedSize)
{throw password;}
return password;
}
void main ()
{
const int legalPasswordSize = 8;
char password[legalPasswordSize + 1];
try
{ strcpy(password, passwordEntry(legalPasswordSize)); }
catch (const char *pswd)
{
cout << "Password is invalid" << endl;
strcpy (password, "*********");
}
cout << "Password is stored as " << password << endl;
}
Jon
|
|
|
|
|
jon_80 wrote: char* passwordEntry(int allowedSize)
{
const int size = 100;
if (allowedSize > size)
{
cout << "Password size is too large. Size limit is " << size << endl;
allowedSize = size;
}
char password[size];
cout << "Enter your password:";
cin.getline(password,size);
if (strlen(password)>allowedSize)
{throw password;}
return password;
}
You return the address of a temporary variable. The scope of password is limited to the function, so when you return it, the memory is not protected anymore.
|
|
|
|
|
I think that I am returning a copy of the variable to a char*, is this the problem?
Jon
|
|
|
|
|
You return the address of the array of char (don't forget that char* is a pointer). This array is created locally in the function (so the memory is reserved in the function). When you reach the end of the function, the array comes out of scope (because its scope is limited to the function). Thus the memory will be freed automaticaly. The contents may still be the same but they are not protected anymore (meaning that anything can override your array). And of course, the pointer that you return still point at the same location (not protected).
You have to take care of the warnings generated by your compiler. Normally, this should have appeared in the warnings ('warning: returning address of temporary variable', or something like that).
|
|
|
|
|
Yes you're right I was overlooking the warning, thanks for the explanation.
Jon
|
|
|
|
|
You really should start using the std::string class. Many of your problems will go away quickly by doing so (or even by using the MFC CString class).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Just a recommendation:
#include <iostream>
#include <string>
#include <exception>
using namespace std;
string passwordEntry(int allowedSize)
{
const int SIZE = 100;
if (allowedSize > SIZE)
{
cout << "Password size is too large. Size limit is " << SIZE << endl;
allowedSize = SIZE;
}
string password = "";
char buffer[SIZE] = {0};
cout << "Enter your password:";
cin.getline(buffer, size);
password = buffer;
if (password.length() > allowedSize)
{
throw exception("Invalid password size!");
}
return password;
}
void main ()
{
const int LEGAL_PASSWD_SIZE = 8;
string password = "";
try
{
password = passwordEntry(LEGAL_PASSWD_SIZE);
}
catch (const exception& e)
{
cout << e.what() << endl;
password = "*********";
}
cout << "Password is stored as " << password.c_str() << endl;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Can anyone tell me how to make a Power ON/OFF button on a VC++ application that controls a radio set AR5000 through its serial interface. The command 'QP' on procomm can turn the radio set OFF and a CR LF will turn it ON.
|
|
|
|
|
|
In my application I have created a propertypage.In that property page I have displayed three edit boxes.
For example in that edit boxes the user will enter name,sex,age.
Taking those three values as column names I have to create a table in the database.
while creating my project I have chosen Database view with file support.
I used ODBC to connect to a datasource.
Can u plz help me.
Thanks in advance.
|
|
|
|
|
Hi,
it seems you have posted the question quite back sometime.
ok. you can use CRecordSet like classes to create tables. before that you may need to connect to the data base using CDatabase class. you can see some samples in MSDN itself.
IMHO, It's better not to attach the database with some controls. because on every change it will update the database. it will slowup the entire application if your application has enough size and others are accessing the database.
you can take the values at the time of update. that would be better.
This is not a solution for your problem but I was trying to explain a good practice.
-Sarath.
The more you can dream the more you can do - Michael Korda"
|
|
|
|
|
Sometimes this [^]would help you
-Sarath.
The more you can dream the more you can do - Michael Korda"
|
|
|
|
|
No need to repost. See here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank you very much for all of you
|
|
|
|
|
Hi,
Can any one help me to write postscript roundedREct function?
Also please write the logic behind the RoundedREct() API in VC++.
Actually i want a dra a rounded rectangle and i have Rectangle parameter and the Horizontal & vertical Radius.
Please help out.
Thanks
Prabbash
|
|
|
|
|
I have not time to do some code. you can do it by Arcs and Lines.
|
|
|
|