A few questions about C++

NINTENDO DS

Well-Known Member
OP
Member
Joined
Jun 10, 2008
Messages
113
Trophies
0
Location
in a mall
XP
-3
Country
United States
It's the first time i use the program, and I am using C++ for dummies.

There is a bunch of complicated stuff.

What do these frameworks mean, and when do I use each one?
//
// Template - provides a template to be used as the starting
// point
//
// the following include files define the majority of
// functions that any given program will need
#include
#include
#include
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// your C++ code starts here
// wait until user is ready before terminating program
// to allow the user to see the program results
system(“PAUSE”);

Also any advice about anything would be nice.
 

Jiggah

Well-Known Member
Member
Joined
Nov 9, 2002
Messages
1,223
Trophies
0
Website
Visit site
XP
279
Country
United States
NINTENDO DS said:
It's the first time i use the program, and I am using C++ for dummies.

There is a bunch of complicated stuff.

What do these frameworks mean, and when do I use each one?
//
// Template - provides a template to be used as the starting
// point
//
// the following include files define the majority of
// functions that any given program will need
#include
#include
#include
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// your C++ code starts here
// wait until user is ready before terminating program
// to allow the user to see the program results
system(“PAUSE”);

Also any advice about anything would be nice.

As the poster above said, what's complicated?

#include - a way of importing header files, classes, and libraries outside of the main program, which contains functions that you want to use in your main program.
cstdio and cstlib - allows you to use read, write, and manipulate files i.e. text files.
iostream - allows you to output and input data. you can't use cout or cin if this is not included. basically, you can't print to the console if you don't include this.

using namespace std; - tells the program where in iostream to look for calls.

int main() - this always needs to be in the program, this is the main body of the program and is usually empty or is void i.e. void main() or int main(void)
int nNumberofArgs, char* pszArgs[] - these are arguments for the main function. One is initialized as an integer and one as a character array.

system("pause") - needed for vc++ 2008, other compilers may not needed it. It tells the console to stop before exiting the program.

You also need to return 0, since it's int main() and not a void main(), and close the main function, which you're missing from that example.

A very basic console program would look like this.

#include
using namespace std;

int main()
{

cout
 

13375p34k3r

Well-Known Member
Member
Joined
Sep 25, 2007
Messages
159
Trophies
0
Age
28
Location
Markham, Ontario
XP
102
Country
Canada
Honestly I would recommend starting to learn programming with Python. It is much more user friendly because it is a high-level interpreted language. That resembles the English language in many ways. Also I wouldn't recommend Visual C++, CODE::Blocks is a much better piece of software that is Open Source.
 

Psyfira

Credit: 0ml. Insert tea to continue
Member
Joined
Dec 31, 2003
Messages
3,886
Trophies
0
Location
England
XP
270
Country
For those "include" statements, they let you use code from other files (called header files). You can write your own header files later on, but C++ provides some for you (for common tasks like reading files, keyboard presses, etc) so you don't have to write it out yourself and that's what is being used here (you have to state which ones you want to use). There's a guide to the provided header files and what they all do here:
C++ Library Reference
Might not make much sense when you're first starting out but stick with it
smile.gif


Also, you might find if you're right at the start of the book it explains them later on. Yes I know it's annoying, I had a lecturer who used to do that (but a lot worse). If you are right at the very start of the book, it should at least be explaining the "main" method now.
 

Joe88

[λ]
Global Moderator
Joined
Jan 6, 2008
Messages
12,736
Trophies
2
Age
36
XP
7,422
Country
United States
int main should be left blank like since your not really doing anything with it (I dont know how the new c++ express works, im just basing this off a VS 6.0)
int main()

lookout said:
 

BigX

Well-Known Member
Member
Joined
Aug 29, 2007
Messages
292
Trophies
0
Location
over there
Website
Visit site
XP
70
Country
Canada
1. OP should think about what he wants to do and why to learn programming
2. C++ is just one mean of software development.
3. If the posted sample is already to complicated, the OP missed some things about software development.

I studied 8 semester of computer science and work for four years after that as software developer. There are still some techniques with C++ not clear to me.
Many people use C/C++ because it is so powerfull. But this power comes with some problems.
If you are able to do anything, the downside is, you HAVE to do anything.
Wherein Java or Python you have "simple" methods for input and output and string operations, performing the same task with C/C++ you'll have to implement (or reuse) some basic stuff.
You should also learn some things about OO (that's object orientation).

Basically explaining the sample code to you would not give you any insight.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    rvtr @ rvtr: Spam bots again.