Just starting up

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Hi.

Hmmm... The sticky that Marauder made is really good, but it is long. One thing that I'd just like to say is that you don't need to use INT for your main() function. The teacher didn't tell us this, but to save time and for just plain convenience:

Code: Select all

int main() {
    return 0;
}
Is the same thing as:

Code: Select all

void main() {
}
You'd only need to return 0; if you were returning the number to another function that does something with it. But since main() is the only one, you are wasting time (a couple of seconds)

Also, I think her aligning of stuff is pretty ghetto. Anything between braces generally gets indented 4 spaces. Actually-- her way of bracing is attrocious to me. I think everybody on these boards uses this style:

Code: Select all

void main() {
    if(something) {
        do something;
        do something;
    }
}
That's our style

This is the old person or ghetto person style:

Code: Select all

void main()
{
    if(something) 
    {
        do something;
        do something;
    }
}
I'm really picky about this type of thing. Maybe I'm just wierd, but that style really gives me a headache.

Post here! Any little question. MarauderIIC is the most knowledgable of C/C++ programming here, I'm in your class and know C++, and JS Lemming knows C++ as well.

Good luck on that horrible ASCII art with printf()s... :nono:

Also, one of the moderators was being stupid and accidently deleted your last post.... :(|):


[/code]
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

C/C++ forums are you friends. Especially the huge ones where people post responces every 3 seconds.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

I respond here randomly within 3 seconds, so there!
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

Yeh im starting c++, too im currently in a c/c++ forumsdevarticles.com there is alot of useful tips/ helps. The only thing taht i dont understand so far is

Code: Select all

 using namespace std;
can someone explain it?
Last edited by Don Pwnious on Thu Sep 02, 2004 9:18 pm, edited 1 time in total.
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

This is C++, so if you're a C whore, ignore it.

the line using namespace std; means that all functions are in the standard include.

When you use cout like this:

Code: Select all

[..]
std::cout << "This is using the Cout function in the standard include\n";
[..]
Now, do you see how every function from that include must have std:: before it?

When you use the command namespace std; you are basically telling it that everything is coming from that include so that you won't have to put std:: in front of your function. You can just do this:

Code: Select all

#include <iostream>

int main() {
    using namespace std;
  
    cout << "OMFG! I don't have to say std:: before this cout!\n";
    return 0;
}
Lemme know if that made any sense. I don't know what you have and haven't learned already, so I'd be glad to explain it again if you didn't understand a part of the explanation.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

evidently I posted the same time Mar did, whoops. Anyway, maybe his explanation is better... :?
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Yeah. Because C/C++ projects can get exceedingly large with a large number of developers, variable names have the potential to overlap. So you can define a namespace, such as MAR_NAMESPACE and then any variables you define in that namespace will have to be accessed by typing MAR_NAMESPACE::variableName. You can also declare functions in namespaces. std is the namespace that <cheaderfile> headers use. Oh, and the whole using statement is so you don't have to MAR_NAMESPACE:: or std:: every time -- it appends it on the variables that require it automatically (in that file). So, using namespace MAR_NAMESPACE; would append MAR_NAMESPACE to variables that require it. And I think you can have more than one using namespace statement, so you can automagically use both MAR_NAMESPACE and std, for example.

So, using namespace std; appends std:: to appropriate variables and functions, because all the headers such as <cstring> and <cmath> and <iostream> and pretty much any standard header that doesn't have a ".h" on the end -- ".h" headers are usually C headers, unless they're user-defined -- anyway, all those header files declare their variables and functions in the std namespace. Phew!

At least check my sticky for links, Itchino! :P
Last edited by MarauderIIC on Thu Sep 02, 2004 9:31 pm, edited 1 time in total.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

Thank you alot, that really helped me, i am currently learning basic input and output
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

OMFG!

Cin and Cout are your friends. If anybody mentions printf and scanf, punch them in the face and tell them you want nothing to do with their C-whorishness!
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

cool thanks,lol, i will tell them that.
Only 33 more lessons
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Take my advice. Don't go through them all. Go to a point where you feel fairly comfortable with C++. Then think of something you want to do or make. Try making it. I'm sure there will be stuff that you haven't learned yet, so go back and read that lesson. Use it as a reference after a a certain point.

I quit actually reading through my C++ book around pointers. Then I used it as a reference...
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Just starting up

Post by Don Pwnious »

ok ill do that

Oh yeah my gay compiler doesn't seem to work, i have no idea where i got it or how to do anything with it. i am trying to get the DEV one but i cant seem to find it.I think it is the one you have SS :?
Last edited by Don Pwnious on Thu Sep 02, 2004 9:44 pm, edited 2 times in total.
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

I have Dev-C++ and Visual C++. Dev-C++ should do you fine, but I think that Visual C++ is the greatest despite the fact that it is like $600...
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

ok i try to get DEV-C++ itll be hard to find because i dont know what mirror site to go to :?
1/8th time- 14secs
1/8th speed - 110mph
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

bloodshed.net iirc

or google
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Locked