Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Straying to C++
#1
Hi all. It's been awhile since I've posted here because I've forayed into the world of C++ programming (sacrilige!).
To all those QB programmers out there who are, like I was, terrified of the thought of having to learn a new programming language, fear not. C++ is unbelievably easy to learn.
I also used to say that C++ is long and tedious to program in, but there isn't really all that much more code to enter.
When I only knew QB, a smooth pixel*pixel scroller with flickerless animation and a 60FPS framerate was a thing of my dreams (being a purist and not liking libraries). I have only been learning C++ for a MONTH and have already accomplished this.

But to the point.... Who else here has found that a solid beginning in QBasic has aided their ability to move on to C++?

Try it! I urge you all. But never forget where you came from.
Reply
#2
I started off in C, couldn't get a damn sample program to compile, and gave up programming altogether until I started playing with QB.


(as for your dreams, check out Quest for a King at http://powerusr.sphosting.com/ for my engine. It gets 60FPS on a 233. Perhaps not the greatest feat ever achieved by human hands, but it *is* pure QB.)

I stick with QB because it's fun and easy to program in. C-alikes can't really say that about themselves. In spite of everything, I can still pick up code from 2 or 3 years ago in QB and understand it, but the same code in C usually has me scratching my head. Just the nature of the syntax.
Reply
#3
Quote:But to the point.... Who else here has found that a solid beginning in QBasic has aided their ability to move on to C++?

Try it! I urge you all. But never forget where you came from.

Yup, I'm working on my 1st C++ game. Or at least, I will be soon Wink Once you can program in any lang, the same basic principles apply. The main diff between these langs is OOP, and once you learn that, Bob's your mothers brother Smile Very useful it is too.
In a world without walls and doors, who needs Windows and Gates?
Reply
#4
YOU FOX! (Er, Piptol AND fox) All I need is some decent string handling routines and a pset, and a PRINT. THEN I'll use C++.

(sorry, your avatar is quite comical)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
If you include the header file "IOSTREAM.H" you can use this for print:

cout<<"Text Here"; same as print "Text Here";

cout<<"Text Here"<<endl; same as print "Text Here"

The pset routine is quite easy (especially if you are using an offscreen buffer) and there is a graphics header call graphics.h which allows you to program in "SCREEN 12". I wrote my own drawing functions for screen 13.

If you need any help email me at:

makk@iprimus.com.au.

I'd be happy to send you a copy of my header files.

You will need somthing like Borland Turbo C++ 3.0 (not MS Visual C++, becasue they don't allow DOS".

As for string functions. I assume you want LEN, INSTR, RIGHT$, LEFT$ etc.

They are all supported in a different way. Some of them you have to write small SUBS for. I have an excellent C++ tutorial I would be happy to send you.
Reply
#6
So you're proposing that "If you include the header file "IOSTREAM.H" and "and there is a graphics header call graphics.h", but you also mentioned this jewel on your first post: "(being a purist and not liking libraries)"

So... are you still a purist? [Image: smoke.gif]
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#7
You having a go mate?

NO I am not a "purist" anymore, and have been grateful to learn the lesson that most lib's are something that you could probably write yourself, but why waste the time when other's have done the work and are so good as to share it with others.

I was on the other side of the fence before, when I didn't think that using libraries in QBASIC code was really kosher. It seemed to me that if you wanted more power you should use a more powerful language, and just accept QBasic for what it is. Now I see the bigger picture.

I'll always be proud of the fact the I can program in QBasic. As we all should be. Peace.
Reply
#8
Peace, bruddah. Nothing personal, I just asked 'cuz I noted that incongruence. And...

"I'll always be proud of the fact the I can program in QBasic. As we all should be."

Feel free to carve that on bronze. [Image: beerchug.gif]
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#9
;*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#10
Quote:To all those QB programmers out there who are, like I was, terrified of the thought of having to learn a new programming language, fear not. C++ is unbelievably easy to learn.
I also used to say that C++ is long and tedious to program in, but there isn't really all that much more code to enter.

Glad to hear people branching out and getting into new languages (the more you know the better). A couple of things strike me as odd in the above quote however. Learning any language (procedural anyway) after you know one already is easy, its a matter of learning the new syntax. eg from QB to C:
Code:
FUNCTION myFunc%(x as INTEGER)
  IF x > 0 THEN
    myFunc% = 1
    EXIT FUNCTION
  ELSE
    myFunc% = 2
    EXIT FUNCTION
  END IF
END FUNCTION
Easily translates into C/C++ as:
Code:
int myFunc(int x) {
  if(x > 0) {
    return 1;
  else
    return 2;
  }
}
However, with a language such as C/C++ there is far more to know than meets the eye at first glance, for instance check out the piece of code I posted in the general section ("A List" thread), its perfectly valid ANSI C code, but its not easy to understand. C has many, many tricks and underlying concepts that can be very difficult to grasp (and no Im not just talking about pointers).

The other thing I find interesting is that you say you find you dont have to do much extra coding in C/C++. This can of course vary depending on how robust your code is. For example.
Code:
typedef struct {
  int a;
  int b;
  char c;
} mem_t;

mem_t *x;

/* Allocate some memory for the mem_t struct */
x = malloc(5);

/* Stuff goes here */

exit(0);
Thats valid working C code, its not too long either, but its not good C code. C and C++ dont do anything you dont ask them too, good stable C code is often longer. The memory allocation above should be replaced as follows:
Code:
if((x = malloc(sizeof(mem_t))) == NULL) {
  fprintf(stderr, "Couldnt allocate memory for mem_t struct\n");
  exit(1);
}

/* Stuff goes here */

free(x);
exit(0);

Note that for portability reasons errors should use fprintf(stderr, "") and memory should be explicitly freed (even though its not always necessary). These things are what makes C code longer than code from other languages such as QB and Java which provide either compiler or runtime protection against many things which C/C++ dont.

That said, C/C++ often allow to code things in very short form also, take the myFunc function above which can be coded in C as:
Code:
#define myFunc(x) ((x > 0) ? 1 : 2)
Of course, writing an entire C program in such terse form can get you into trouble, check out http://www.ioccc.org/ for examples.

Get a good book on C/C++ from your local library (not an internet tutorial) and read it from cover to cover. C and C++ are /very/ powerful languages, but they do take a bit more learning effort than many other languages if you want to use them effectively and correctyly. Happy coding :lol:
esus saves.... Passes to Moses, shoots, he scores!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)