PDA

View Full Version : New C++ Programmer Needing Help and Advice..?



VenomousDesigns
8th December 2004, 08:14 AM
Good evening,

I have been looking at starting a Coding Lanuage for a long time now that would be in toe with where I want my career to go, Games Programming. I have had many suggestions, read many articles and chatted with programmers near and far, the 2 possible lanuages/programs that have been suggested to me time and time again have been C++ and Maya.

With the recent Games conference in Melbourne, Australia, I yet again had a chance to read up and try and sit back and figure out which way to go and finally came to the conclusion to ask the guys that are actually out there coding for livings or as a general hobby.

I have just recented purchase a few C++ Books/How to's and just downloaded Dev-C++ by Bloodshed Software. But just last night I gave my had at the legeandary "Hello World" program which is a must for all would-be coders and beginners and I have already found myself unstuck..

After typing the following into a blank Source File in Dev-C++, all that was produced after compiling and running it was a Command Prompt window which would appear and disappear within the time spand of 2 seconds:


#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}

Im sure it is something I'm doing as a novice C++ programmer and am looking to you guys for guidance if this (C++) is the right direction for a furture Games Programming and if you guys would mind taking the time to reply and point me in the direction of any useful sources (If it be Books, Sites, Schools, Programs etc) it would be greatly appricated.

Also I would like to hear from any students currently studying or finished a Games Programming course and It would be great to discuss how you think the Games Industry is going in ways of which programs to use to achieve the high levels of Programming we are seeing used to produce such fantastic games today and in the future.

Yours Sincerly,

VenomousDesigns

mooninite
8th December 2004, 09:20 AM
I don't think I saw a question mark in your post, so I'll just throw out some terms you'll need to get familiar with:

Classes
Templates
Data Structures (STL or Standard Template Library)
etc.

C++ is not a very easy language in any stance. There is just too much of it to understand, heh.

I've never used Dev-C++ but I'm not sure what OS you want to program for. Linux or Windows?

tashirosgt
8th December 2004, 04:01 PM
If you are working in a "development environment" you may get different behavior than the typical C++ book expects. Try compiling and running the program in a terminal window. (I did and it works.)

jtang613
8th December 2004, 04:18 PM
First, Dev-C++ is Windows software, but somehow this post made its way to a Linux forum. Try Anjuta for Linux.

But to answer your question, the behaviour you are seening is most likely the proper and correct execution of the program. Explanation: the output window opens then the program prepares to run - this takes 1.999sec of the 2sec you referred to. Then the program executes and terminates, thus closing the output window before you have a chance to see the output.

Try adding: getch(); or getchar(); immediately after the cout statement.

That being said, C++ is a powerful language and has the ability to really take you places. It is definately the language of choice for game programmers. Maya, on the other hand, is a 3D Design application, not a programming language (afaik). Although it most likely does have an SDK/API (software developtment kit - C++ libraries) to facilitate game and application development.

VenomousDesigns
8th December 2004, 04:41 PM
Thank you for your replies,

Yes I am currently booting Windows but have used and would rather be using Linux (Fedora) but as Mircosoft has the corporate world by the balls I am forced to use Windows.

Are you able to suggest any other programs that maybe I would be better starting with as a novice? I mean I don't want Dev-C++ doing all the work for me being an IDE so I'd be much happier using a program, say that they use in the industry so I could be practing on south more meaningful...?

Yes Im happy to take any pointers, suggestions or cirticism to work out the best route for me to take on this longer, hard but important journey done C++ and into the further

Just on a side note, One of the books I currently have is a "Teach Yourself in 21 Days C++" which looks quite reliable for a novice, please by all means suggest programs, sites or books because I am by all means happy to purchase them if they are the right thing that could help

Thanks,

Venomous Designs

wallace
8th December 2004, 04:50 PM
For a new comer I would recommend


turbo C++ By Robert Lafore


I have learned C++ using this book. It does not require any prior knowledge of programming, and that's where it hits !

Happy Coding

tashirosgt
8th December 2004, 05:22 PM
VenomousDesigns,

You didn't say whether you had done programming in other languages. If not, your basic problem is "learning to program" rather than "learning to program in C++" and this is usually a problem of finding some way of doing it that provides self-motivation and encouragement. You want to see results quickly and not get stuck and discouraged at places. If games are your interest, you probably want an approach that quickly gets to some pictures. I'd say it is hard to find such an approach with C++ unless you use a "development environment". For example if you want to draw a picture in Linux "from scratch" as it were, you need to know a little about X Window System programming. If it is 3d, you need to know how to use something like OpenGL. If you are just getting started and want to see some pictures quickly, you might try Java instead of C++. Java is like a tame (some would say "sane") version of C++.

Chas.H
8th December 2004, 05:43 PM
After typing the following into a blank Source File in Dev-C++, all that was produced after compiling and running it was a Command Prompt window which would appear and disappear within the time spand of 2 seconds:


Actually, if you start from a command prompt in the first place and run the executible by typing, ./filename you would eliminate that problem.



Try adding: getch(); or getchar(); immediately after the cout statement.


These are actually a Borland (Turbo C/C++) functions that are not included in standard C or C++

Hint:
using namespace std;
put the above line near the beginning of your code before the main() and you won't have to scope your std functions
std::cout << becomes simply cout <<

VenomousDesigns
9th December 2004, 02:04 PM
Hi,

I have had previous knowledge in Visual Basic's but I wouldnt be confident in saying I could program anything more then a simple program.

In response to becoming easily bored and giving up, I am not interested in seeing pictures come together as when coding Games you never get to see anything more then a rough Stick Figure anyway until it gets passed onto the Graphic/Art Department for Skinning. So there is no worry from me giving up on this subject as I have been wanting to go into this for a long time now.

Alos in response to Turbo C++, The only reason I didnt get this is as Chas. H said quite rightly that it hasn't got some features/code of the mainstream C++ Lanuage. I am only concerned with learning the mainstream C++ so I'd be able to maybe down the line move onto C, C# etc when I have the general knowledge of C++.

I still havern't heard back if Dev-C++ is the best program to be learning on as I have already encounted a problem with it, with the simple "Hello World" program. Could you guys suggest any other programs to use and/or books too to learn from?

Referring back to the "Hello World" program adding


getchar();

After the cout statement fixed the problem of it disappearing, I was wondering if I will have to add this to every program I compile or is there a reason why Dev-C++ or "Teach Yourself C++ In 21 Days" didnt include this?

Thanks

Venomous Designs

jtang613
9th December 2004, 02:59 PM
The '21 Days' books are a great beginners series. I've read the exact book several years ago in preparation for college. In addition, try The Waite Group's 'Object Oriented Programming in C++', (ISBN 1-57169-160-X) published by SAMS. It covers some slightly more advanced topics in better detail. If you read (and understand) both of those - cover to cover - you'll definately have the tools you need begin writing intermediate programs.

Of course, these books really only teach syntax and form. But most programmers know that there's much more to it. Look for books on Data Structures (trees, lists, tables) and Algorithm Design (sorts, searches, hashes, etc). And get to know your libraries - iostream is the tip of a very big iceberg. Chances are, if you can think of it, someone has written a template/class/method for it.

If you plan on targetting the Windows platform, then nothing beats Visual C++. You can often find it packaged with the book 'Visual C++ .NET Step by Step' (ISBN: 0-7356-1907-7) - which I highly recommend to get you started with Windows GUI programming.

Linux is slightly different in that most of the best information is free and easy to find on the web. Anjuta is the IDE I use, but others use KDevelop. They're both frontends for the GNU C/C++ compiler 'GCC'.

Other things to think about are: exploring the DirectX SDK and OpenGL SDK documentation, and downloading the source for a GNU game (such as Tuxracer) to see what makes it tick. Also consider visiting your local college to see what courses they offer. It is true that *some* people teach themselves everything, but college (or even university) programs in Computer Science will do a significantly better job, without question.

About the getchar();
There is often an option to 'leave output window open' in the IDE's preferences menu. This would eleminate the need for a getchar(), which, as you begin writing more complex programs, is not the best solution.

hth,
Jason

engwnbie
9th December 2004, 03:26 PM
This quick tutorial at http://www.cprogramming.com/tutorial/lesson1.html expains why you program exited, better than I can explain.

Myra
9th December 2004, 07:06 PM
Yes I am currently booting Windows but have used and would rather be using Linux (Fedora) but as Mircosoft has the corporate world by the balls I am forced to use Windows.


Have you looked at SDL? It's a cross platform API for creating media applications like games. Combining this with OpenGL and Maya, you can create professional quality games.

Also, DirectX (in traditional MS fashion) is needlessly overly complicated, it takes pages of code to initialize graphics and most of that code is setting unused parameters in structs to null or setting convoluted members in data structures to obscure values. With SDL it's very straight forward.

But as you're still with your first hello world program: good luck!

GreyGeek
9th December 2004, 07:54 PM
Thank you for your replies,
... but as Mircosoft has the corporate world by the balls I am forced to use Windows.


No, Microsoft doesn't. Bill Gates didn't put a gun to your head and demand that you program for WinXX and use WinXX tools. Neither does the fact that most gamers still use the WinXX environment. You still have the option to choose. In fact, the Linux desktop is exploding right now, and this is the ground floor, the time for Linux gaming programmers to hop on board!

Ther are some steps you need to take:
1) Install Linux as a dual boot on your PC (or make it your sole OS!). I'd recommend FC2 (give FC3 a little time to mature. Or, download the free 2 ISO set from LibraNet and install it. It is Debian based but includes about everything including Glade (for the GNOME desktop) and KDevelop (for the KDE desktop) and even configures and installs 3D acceleration for nVidia cards (ATI?) automatically during the install. If you're really agressive give Gentoo a try.)

2) Get a good C++ programming book that focuses on the Linux platform. The book by Tom Swan is one I used specifically because it is focused on Linux.
http://www.amazon.com/exec/obidos/tg/detail/-/0789721538/103-7933235-8715026?v=glance

Swan uses a simple text editor but also includes some sections describing emacs, and other tools. I wouldn't choose a programming tool (IDE or GUI RAD) UNTIL AFTER you finish the Swan book and feel comfortable programming using a simple editor, creating Makefiles, and using the gcc, linker and debugger on the command line. Otherwise, more powerful GUI RAD tools like KDevelop, which is my favorite, will be a blackbox which, when you have problems, will be unfathomable. Later, as your programs become more complex and have many kinds of files (headers, source, resources, ui's, etc...) an IDE or GUI RAD is indespensible.

3) Chose your gaming API. This will also determine your GUI widget set, if any. QT is a popular choice, but if you write gaming apps for the commercial market then Tolltech will want a slice of your pie, otherwise you can use their widget set to your heart's abandon. The C++ API includes graphics objects, and they may be all you want or need. After you install Linux and have a 3D video card running you can take a look at the various 3D games (and there are many) available for Linux. Games like Pool, Table Tennis, etc., are Open Source and include the source, so you can see how they do what they do. Maybe even build on their work, in the true spriit of the GPL.

4) Never, ever give up. You'll get discouraged, but roll with it, do a distraction for a while, but for certain return to the task. I don't know what your native intelligence is, but I have taught hundreds of kids to program (retired HS&College Sci Prof) and all can learn to one degree or another. You may not achieve Linus Torvalds' ability, but you'll certainly be better than a quitter. And, who knows, once your talent takes off you may see code in your head like Motzart saw music! :)

bretzel
9th December 2004, 08:22 PM
Hi, ( sorry for my low english skill )

I don;t know how fast you learn but in my experiences,
--as I begun learning programing in BASIC on a (feu) Commodore 64, and then in assembly language on the same C64 and C128 and then on the Amiga; on PC: PASCAL and finally C and C++ a couple of years later, --
The most difficult aspect of C++ I had to deal with was the unique and powerfull "template" feature of the c++ language, wich is the core brain of the STL libs. To understand how abstract it can be, have a look at http://ndk-xx.sourceforge.net/ : the ALT-Branch and then view the API Documentation ...

I've ve got a book I yould like to suggest you for learning data structure. It is certainly NOT the best book about this topic but the Writter has the bright idea to explain the " c++ template classes" from scratch, without the famous complex STL. Thus That book helped me to at last to understand
how templates work in all aspects such as syntax; inheritance; expansions and expressions in C++ world. And then regarding Data structures in C++, This topic is in the book title :-)

Here the Book's data:
Title: Object-Oriented C++ Data Structures for real progammers
Author: Jan Harrington
Editor: MORGAN KAUFMANN (MK)
ISBN: 0-12-326429-2
:-)

Welcome to the C++ world!
Good luck and happy c++ coding!

Bretzel

engwnbie
10th December 2004, 12:14 AM
If you are running FC install development software and try "kDevelop"

Chas.H
10th December 2004, 04:30 AM
VenomousDesigns,
If you really need getchar() to keep the window open I would suggest you substitute cin.get() because this is standard C++ and should work in any compiler worth its salt.

Shadow Skill
18th December 2004, 08:51 AM
You know my old high school professor mentioned using cin.getline() as a substitute for getch() because getch() could act very evil when mixed with cin statements. I have never seen cin.get() before though. I learned something today I guess. :) I actually came to this part of the forum this morning planning to ask simillar questions except I am more interested audio manipulation, such as opening and closing mp3 files, reading tag data, displaying bit rates properly etc. Then I saw this thread and thought "this guy is in a simillar situation. Why not see what others have suggested to him." Good thing I did too I think I will go ahead and order the book Grey mentioned, as my two main problems right now are that I am easily distracted and I am not really familliar with Linux c++ programming so trying to pick up where I left off has been a real pain in the butt. Good thing is my real classes are about to start soon and although it is .net centric I will be immeresed in situations that will really require me to get up on my coding ability [what little I had of it anyway.] can any of you point me to Linux specific info on manipulating audio files such as mp3's in the manners I described earlier?

lech
20th December 2004, 05:54 PM
@VenomousDesigns

I'm just starting out with linux programming I found these interesting links on the www, also bought a book on the subject.

# very nice C tutorial,
http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html

# C programming course
http://www.its.strath.ac.uk/courses/c/

# a free book on programming C++ (expects you to have some previous programming experience)
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

You could develop under cygwin(cygwin.com) on MS WIndows and still use GCC, this should be sufficient for getting down the basics.

Please note that (game)programming is an art and is not something you will be able to learn overnight, start with the basics and keep at it... ;)

Lech

Jambi
23rd December 2004, 05:05 AM
Try here Hotscripts (http://www.hotscripts.com/C_and_C++/index.html)

It helped me

harlequin
23rd December 2004, 10:48 AM
In windows to get the program running so that you can see the output, is to compile the program, get a command prompt up, navigate to the directory where trhe compiled program is, and type the program name in at the prompt.

To do the same in linux is much easier. (Be aware that I only know how to compile C programs using gcc, but my understanding is that it'll work for C++ proggies too) Navigate to the folder where your source file is stored, type 'gcc -o <insert program name> *.cpp' this will compile all the cpp files in that directory to give you the program. To run the program type './<insert program name>' with any inputs that you need.

I'll add this to the list of C related links. It's a guide to the C libraries that are avaliable.
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/index.html

This is a C FAQ
http://www.eskimo.com/~scs/C-faq/top.html

This is a C++ tutorial site
http://www.desy.de/gna/html/cc/Tutorial/tutorial.html

I hope this helps.

Chas.H
23rd December 2004, 05:20 PM
This is what I was trying to get accross on my earlier post. Since a terminal window is open before the programme is run, it will stay open after execution. So a simple "Hello World" doesn't run and disappear before you can see it. This eliminates the need fot cin.get() to hold the window open.

Rule of thumb:
If a programme is meant to run in a command line, launch it from the command line.

veritas
12th January 2005, 10:03 PM
I am interested in learning c++ also. I wonder about a quick vote on best gui to start with? anyway, I was going to suggest a very different approach. If you still have Windows, why not get a copy of neverwinter nights, the game? It runs on Linux, but the toolset does not. the toolset lets you build your own modules. While much can be done with point and click, you can get in and script at whatever your comfort level is. It is their own programming language, but it is based on C++ and the basics are easy to learn with tutorials. the best part is the quick feedback. Even when using the wizards, you see the code that is generated and can change it. Of course, much of the detail will be very specific to NWN, but it is a great way to get a taste of the way programming works in a gaming environment.

DevinSmittle
9th July 2005, 10:02 AM
You can also use

system("PAUSE");