|
From: Daniel G. <sp...@ho...> - 2002-04-17 10:04:29
|
when you enumerate variables, is the first one (by default) 0 or 1 ? _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com |
|
From: Bob W. <bo...@ph...> - 2002-04-17 12:01:21
|
Daniel;
when you enumerate variables, is the first one (by default) 0 or 1 ?
Run this little program and you will get your answer.
#include <iostream.h>
#include <conio_mingw.h>
#include <stdio.h>
// #include <windows.h>
// #include <stdlib.h>
// #include <time.h>
enum {Dog,Cat,Horse,Pig};
int main (int argc, char *argv[])
{
int i;
for (i =3D Dog; i <=3D Pig; i++)
std::cout << "i =3D " << i << std::endl;
std::cout << "\n\nHit any key to close window . . .";
while (!kbhit());
return 0;
}
|
|
From: Jason H. <jas...@bt...> - 2002-04-17 14:27:55
|
The default is 0, and then each consequtive one is +1 the previous one. =
You can change the value of an enum by initialising it to something =
else, i.e.
enum farmyard {cow, sheep, pig, chicken, fruitbat =3D 1000, elephant, =
pigmi}
so cow =3D 0, sheep =3D 2, etc.. and then fruitbat =3D 1000, elephant =
=3D 1001, and so on.
Jason.
----- Original Message -----=20
From: Bob Wilson=20
To: Dev-C++ User Mailing List=20
Sent: Wednesday, April 17, 2002 1:02 PM
Subject: Re: [Dev-C++] enum
Daniel;
when you enumerate variables, is the first one (by default) 0 or 1 ?
Run this little program and you will get your answer.
#include <iostream.h>
#include <conio_mingw.h>
#include <stdio.h>
// #include <windows.h>
// #include <stdlib.h>
// #include <time.h>
enum {Dog,Cat,Horse,Pig};
int main (int argc, char *argv[])
{
int i;
for (i =3D Dog; i <=3D Pig; i++)
std::cout << "i =3D " << i << std::endl;
std::cout << "\n\nHit any key to close window . . .";
while (!kbhit());
return 0;
}
|
|
From: Ioannis V. <no...@ho...> - 2002-04-17 18:14:17
|
A more ANSI C++ compliant code would be:
#include <iostream>
#include <cstdlib>
int main ()
{
using std::cout;
using std::endl;
using std::system;
enum {Dog,Cat,Horse,Pig};
int i;
for (i = Dog; i <= Pig; i++)
cout << "i = " << i << endl;
system("pause");
return 0;
}
or check the comments i have placed in your code.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
<http://www.noicys.cjb.net/>
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Bob
Wilson
Sent: Wednesday, April 17, 2002 3:03 PM
To: Dev-C++ User Mailing List
Subject: Re: [Dev-C++] enum
Daniel;
when you enumerate variables, is the first one (by default) 0 or 1 ?
Run this little program and you will get your answer.
#include <iostream.h>
#include <iostream>
#include <conio_mingw.h>
Not portable.
#include <stdio.h>
Not needed.
// #include <windows.h>
Header file for system extensions. Non needed.
// #include <stdlib.h>
// #include <time.h>
Not needed.
enum {Dog,Cat,Horse,Pig};
int main (int argc, char *argv[])
{
int i;
for (i = Dog; i <= Pig; i++)
std::cout << "i = " << i << std::endl;
std::cout << "\n\nHit any key to close window . . .";
while (!kbhit());
Not needed system extension.
return 0;
}
|
|
From: Bob W. <bo...@ph...> - 2002-04-18 13:06:45
|
MessageI've been think about this, and isn't the call to =
system("pause"); a windows specific call and as such would not be =
portable to UNIX or any other operating system?
Regards,
Bob
A more ANSI C++ compliant code would be:
#include <iostream>
#include <cstdlib>
int main ()
{
using std::cout;
using std::endl;
using std::system;
=20
enum {Dog,Cat,Horse,Pig};
int i;
=20
for (i =3D Dog; i <=3D Pig; i++)
cout << "i =3D " << i << endl;
=20
=20
system("pause");
=20
return 0;
}
=20
or check the comments i have placed in your code.
Ioannis
|
|
From: Ioannis V. <no...@ho...> - 2002-04-20 17:47:47
|
Yes, the pause argument is system depedent, but the system() function
can be found to any system. You simply change "pause" to the correct
command of any system. I would do the following:
// system extension encapsulated under a portable interface
void pause()
{
system("pause");
// or sleep() or whatever
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
<http://www.noicys.cjb.net/>
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Bob
Wilson
Sent: Thursday, April 18, 2002 4:08 PM
To: Dev-C++ User Mailing List
Subject: Re: [Dev-C++] enum
I've been think about this, and isn't the call to system("pause"); a
windows specific call and as such would not be portable to UNIX or any
other operating system?
Regards,
Bob
A more ANSI C++ compliant code would be:
#include <iostream>
#include <cstdlib>
int main ()
{
using std::cout;
using std::endl;
using std::system;
enum {Dog,Cat,Horse,Pig};
int i;
for (i = Dog; i <= Pig; i++)
cout << "i = " << i << endl;
system("pause");
return 0;
}
or check the comments i have placed in your code.
Ioannis
|
|
From: Ioannis V. <no...@ho...> - 2002-04-17 17:52:36
|
0 Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Daniel Glenfield > Sent: Wednesday, April 17, 2002 1:04 PM > To: dev...@li... > Subject: [Dev-C++] enum > > > when you enumerate variables, is the first one (by default) 0 or 1 ? > > _________________________________________________________________ > Chat with friends online, try MSN Messenger: http://messenger.msn.com > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |