Title: Newbie header file
Description: to simplify things
Shadow of the Moon - September 7, 2003 12:31 AM (GMT)
I decided to work on a header file that would make things more understandable for people who are new to C++. This one is for consoles. I'll probably make a win32 one too eventually. It is really just a bunch of Macros that make things more readable. I intend to add to it, so if you have any suggestions, fire away.
<EDIT>
I need to overhaul the header. the version the link went to sucked, so I took it down.
dr voodoo - September 7, 2003 10:44 AM (GMT)
| CODE |
#define ask_for_string(string a, string b) cout<<a; cin<<b; #define ask_for_integer(string a, int b) cout<<a; cin<<b; |
Shouldn't that be
| CODE |
#define ask_for_string(string a, string b) cout<<a; cin>>b #define ask_for_integer(string a, int b) cout<<a; cin>>b |
I removed the last ; because else you would not need to put a ; behinde the macro evocation.
Also I don't think that macros are a good idea because if you make some code error the compilers says that cout<<a; cin>>b is wrong instead of ask_for_string(string a, string B). But that's just me.
Shadow of the Moon - September 7, 2003 12:56 PM (GMT)
Yeah I realized that macros are not the best idea for some of the functions. I redid some of it and will upload an updated copy soon.
shortys team - September 7, 2003 02:17 PM (GMT)
you could use
| CODE |
#include <iostream.h> #define print(x, n) cout<<x; if(n!=0) cout<<"\n"; #define input(x, n) cin>>x; if(n!=0) cout<<"\n";
|
then all you would have to do is put
#include <easycpp.h>
int main()
{
int name;
print("entyer your name", 1);
input(name, 0);
return 0;
}
TheHawgMaster - September 7, 2003 02:31 PM (GMT)
There are two KeyWords I think you should know about: typedef and inline.
USE INLINES! JUST LOOK AT ONE OF THE ERRORS CAUSED BY YOUR min:
| CODE |
| integer i = 5 + min(2 + 1, 6); |
Gets evaluated to:
| CODE |
| integer i = 5 + 2 + 1 < 6 ? 3 : 6; |
I think you can see the problem... You can fix it by putting perenthesis around the arguments like this:
| CODE |
| #define min(a, b) ((a)<(b) ? (a) : (b)) |
But then imagine if you did this even then:
| CODE |
integer a = 3; integer i = min(a++, 6); |
LOL a ends up being 5, and that's a problem you can't get around. USE INLINES!
Shadow of the Moon - September 7, 2003 03:06 PM (GMT)
The header I have up there now is crap. I'm having problems with my updated version. I'm taking the first one down.
ih8censorship - September 7, 2003 03:07 PM (GMT)
if you can try to make it as much like gml as possible. remember most of our members and future members were/are into gml.
Kylevision - September 26, 2003 10:18 PM (GMT)
Heh I made a header file like this such a long time ago..psuedo code...brings me back to the good old days...