|
"What to do use arrays for?"
is this english ?
|
|
|
|
|
While it is bad grammar, yes it is certainly English.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
#hackC++ wrote: What to do use arrays for?
To hold more than one of an item.
#hackC++ wrote: please give an example.
An array of baseball cards, phone numbers, computer names, songs, etc.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
After reading an article on CP about exceptions, I wanted to test efficiency of exceptions compared to normal error checking by using the following program, but when run in debug mode it says there is an unhandled exception. What am I doing wrong ?
<br />
#include "stdafx.h"<br />
<br />
using namespace std;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
DWORD dwStart = ::GetTickCount();
const int x = 1000000;<br />
const int xEnd = -x;<br />
int y = x;<br />
int z;<br />
<br />
while ( y > xEnd )<br />
{<br />
try<br />
{<br />
while ( y > xEnd )<br />
z = x / y--;
}<br />
catch (...)<br />
{<br />
cout << "Divide by zero" << endl;
y--;
}<br />
}<br />
<br />
DWORD dwStop = ::GetTickCount();<br />
DWORD dwDiff = dwStop - dwStart;<br />
char csMessage[100];<br />
sprintf(csMessage, "mSec = %d\n", dwDiff);<br />
cout << (LPCTSTR)csMessage << endl;<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
interesting.
did u see output cout<<...?
if not, i guess "catch" can not catch num/0 because CPU can not treat things like this.
|
|
|
|
|
Because dividing by zero is a hardware exception not a language exception - this is the way C++ is supposed to behave. MSVC6 got it wrong. Newer versions have the /EHa switch to switch to the old non-standard behaviour.
Steve
|
|
|
|
|
Thanks for the info Steve. I'm haven't really used exceptions before, so I'm trying to understand when they should be used and when they shouldn't be used.
However, it did not completely solve the problem. When using the /EHa switch, the exception seems to get caught, but the catch{} handler is not called (ie. the message is not printed out). I tried using Microsoft own example below, but again the message "Caught an exception in...." is not displayed. Why isn't the catch(...){} block being executed ?
Also, since hardware exceptions should not be caught in standard C++, what would be the correct way to handle such an exception (eg. divide-by-zero) in a standards compliant way (eg. using if (0 == y) checks ?) ?
#include <iostream><br />
#include <excpt.h><br />
using namespace std;<br />
<br />
void fail() {
try {<br />
int i = 0, j = 1;<br />
j /= i;
}<br />
catch(...) {
cout<<"Caught an exception in catch(...)."<<endl;<br />
}<br />
}<br />
<br />
int main() {<br />
__try {<br />
fail(); <br />
}<br />
<br />
__except(EXCEPTION_EXECUTE_HANDLER) { <br />
cout << "An exception was caught in __except." << endl;<br />
}<br />
}
|
|
|
|
|
Hi
I'm working in a two way authentification system, that replaces the GINA.
The problem I had found with the beta testers, is that they don't really know their user and passwords, because XP always remember their names, or if they are the only one user, XP don't even ask them to login.
The outcome of all this, is that once installed the new GINA and they reboot the machine, they can't login anymore.
So, the question is...
Is any way an application can check if the user and password are valid?
Thanks in advance
|
|
|
|
|
Doing a random project for school. blah. Been fighting with it and I'm sure I'm missing some little problem and my buddies who usually read over my code for me are out of town for the week. Yay for procrastination! Anyway, if anyone can spare 5 minutes to look it over. It's about 90% done, couple bools need to be made useful, but I need to figure out the following errors :
error C2228: left of '.append' must have class/struct/union type line 25
error C2228: left of '.chop' must have class/struct/union type line 35
error C2228: left of '.print' must have class/struct/union type line 45
Main file
#include <iostream>
#include "class.h"
using namespace std;
void main ()
{
int n;
int elem;
int pointedArray[10];
int *array = 0;
bool completion = false;
elem = 10;
for (n = 0; n < elem; n++)
{
cout << "Enter value for element " << n+1 << " of the array : ";
cin >> pointedArray[n];
}
array = &pointedArray[0];
Array ar1 (int array[], int elem);
completion = ar1.append();
if (completion == true)
{
cout << "Append successful!" << endl;
}
else
{
cout << "Append Unsuccessful!!" << endl;
}
completion = false;
completion = ar1.chop();
if (completion == true)
{
cout << "Chop successful!" << endl;
}
else
{
cout << "Chop Unsuccessful!!" << endl;
}
completion = false;
completion = ar1.print();
if (completion == true)
{
cout << "Print successful!" << endl;
}
else
{
cout << "Print Unsuccessful!!" << endl;
}
completion = false;
system ("pause");
}
Header File
#include <iostream>
using namespace std;
int i;
class Array
{
private:
int element;
int *pArray;
bool extend();
bool contract();
public:
Array ( );
Array (int array[]);
Array (int elem);
Array (int array[], int elem);
~Array () {}
bool append();
bool chop();
bool print();
bool success;
};
Array :: Array ( )
{
pArray = 0;
}
Array::Array (int array[])
{
pArray = &array[0];
}
Array::Array (int elem)
{
pArray = 0;
element = elem;
}
Array::Array (int array[], int elem)
{
pArray = &array[0];
element = elem;
}
bool Array :: append()
{
success = extend();
cout << "Please input new element value: ";
cin >> pArray[10];
return (true);
}
bool Array:: extend()
{
int temp[11];
for(i = 0; i < (element); i++)
{
pArray[i] = temp[i];
}
pArray = &temp[0];
return (true);
}
bool Array :: chop()
{
success = contract();
return (true);
}
bool Array:: contract()
{
int temp2[9];
for(i = 0; i < (9); i++)
{
pArray[i] = temp2[i];
}
element -= 1;
pArray = &temp2[0];
return (true);
}
bool Array :: print()
{
for (i = 0; i < element; i++)
{
cout << "The value of element " << i << " is " << pArray[i] << endl;
}
return (true);
}
With modifications per request
-- modified at 12:33 Tuesday 25th April, 2006
|
|
|
|
|
Surround your code snippet with <pre> tags, check indentation, make sure #include directives are visible, and lastly, click the Preview button first before posting.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
JarethAshaer wrote: error C2228: left of '.append' must have class/struct/union type line 25
error C2228: left of '.chop' must have class/struct/union type line 35
error C2228: left of '.print' must have class/struct/union type line 45
Makes me think that something is wrong with your declaration of ar1.
JarethAshaer wrote: Array ar1 (int array[], int elem);
get rid of the two int keywords in this declaration.
|
|
|
|
|
no go with the int. I forgot to put in that if I use the default constructor (I.E. Array ar1();) the program works.
|
|
|
|
|
I am not sure we are talking about the same thing. This is the code that I am referring to
<br />
...<br />
array = &pointedArray[0];<br />
Array ar1 (int array[], int elem);<br />
completion = ar1.append();<br />
...<br />
remove those int keywords.
|
|
|
|
|
I did. I changed it to Array ar1 (array[], elem); and it didn't work
also, if I just have Array ar1; the program works
|
|
|
|
|
First, looking at your code, I think if you examine the content of ar1 after you use the default constructor you will find that the 10 elements you wanted to add are not there. You may want to change your print statements to give better confirmation that your program worked.
Second, if you find what I said correct, I think you should find that
Array ar1(array, elem);
is the proper declaration for what it appears that you are trying to do.
Third, keep up the good work.
|
|
|
|
|
well, yes, the program worked, but I got long strings of memory cell locations. Scientific notation is a good sign something didn't work I just meant that the rest of the program was in working order.
|
|
|
|
|
Hi
especially i want to know what .lib file is ,what information it contains.
When does compiler generate .dll file and what we done so compiler generate .lib file?I really don't understand the differences.(for example gdi32.dll and gdi32.lib)
I am looking for your answers.
Thanks.
-- modified at 11:13 Tuesday 25th April, 2006
|
|
|
|
|
gdi32.lib is a static library that contains simple functions that simply pass the parameters through to the gdi32 DLL. it lets programmers link to the DLL as if it was a static library, so they don't have to worry about LoadLibrary/GetProcAddress/etc..
rotorcli wrote: When does compiler generate .dll file and what we done so compiler generate .lib file?
if you have a DLL project, there's a compiler/linker setting you can use to turn on .LIB generation.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Hmm so when we use cout() we use static library but when we use Rectangle() in gdi32.dll we use dynamic library and dynamic binding.
So can we say if we use static libnrary we need libraries header file(.h)because compiler must see the function's parameter list but when we use we do not need header files?
Is it true?
|
|
|
|
|
rotorcli wrote: So can we say if we use static libnrary we need libraries header file(.h)because compiler must see the function's parameter list but when we use we do not need header files?
yes, that's true. the compiler doesn't know anything about functions you load with GetProcAddress.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Thanks for answers.
I have one more and last question.
I know that we can linking dlls by staticly or by dynamicly.(If this is not true please warn me).
When Linking dynamic linking libraries dynamicly(at run-time) we do not need header files of that dll.
But if we lnking dynamic linking libraries by staticly(compile-time), do we need header files too(like linking static library)?Or dont we need header file?
Can you give me please some information about that.(about linking dll staticly , dynamicly and header files)
Thanks again.
|
|
|
|
|
I'm trying to compile my first console app with VC++ 2005 Std and it has the following error
c:\program files\development_tools\microsoft visual studio\vc\platformsdk\include\winnt.h(3857) : error C2146: syntax error : missing ';' before identifier 'ContextRecord'<br />
Any ideas ?
|
|
|
|
|
Defenestration wrote: Any ideas ?
Yes, a ';' is missing before the identifier 'ContextRecord'.
If you don't provide more information (like some code around the line at which the error occur) we won't be able to provide you with a solution.
Error message in general are very explicit. If you get a message like that, I'm almost sure it is not because you forgot to plug your computer
|
|
|
|
|
When I look at the winnt.h include file, the struture where PCONTEXT is defined is greyed out, which means that it's being conditionally compiled out. This is defined differently depending on whether the preprocessor constant _X86_ or _AMD64_ is set. In my case neither is being set.
Would I be right in thinking that this needs to be manually set depending on whether you are targetting 32-bit or 64-bit ?
|
|
|
|
|
Solved the problem... It was because I had
#include <windef.h>
before
#include <windows.h>
I just removed the windef.h one and everything's OK
|
|
|
|