Page 1 of 5

Posted: Mon Aug 16, 2004 10:31 pm
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]

Posted: Tue Aug 17, 2004 3:45 pm
by JS Lemming
C/C++ forums are you friends. Especially the huge ones where people post responces every 3 seconds.

Posted: Tue Aug 17, 2004 3:55 pm
by Falco Girgis
I respond here randomly within 3 seconds, so there!

Posted: Thu Sep 02, 2004 9:18 pm
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?

Posted: Thu Sep 02, 2004 9:28 pm
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.

Posted: Thu Sep 02, 2004 9:29 pm
by Falco Girgis
evidently I posted the same time Mar did, whoops. Anyway, maybe his explanation is better... :?

Posted: Thu Sep 02, 2004 9:31 pm
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

Posted: Thu Sep 02, 2004 9:32 pm
by Don Pwnious
Thank you alot, that really helped me, i am currently learning basic input and output

Posted: Thu Sep 02, 2004 9:33 pm
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!

Posted: Thu Sep 02, 2004 9:37 pm
by Don Pwnious
cool thanks,lol, i will tell them that.
Only 33 more lessons

Posted: Thu Sep 02, 2004 9:39 pm
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...

Just starting up

Posted: Thu Sep 02, 2004 9:44 pm
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 :?

Posted: Thu Sep 02, 2004 9:48 pm
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...

Posted: Thu Sep 02, 2004 9:51 pm
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 :?

Posted: Thu Sep 02, 2004 9:57 pm
by MarauderIIC
bloodshed.net iirc

or google