Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Help with C++


ghost's Avatar
0 0

I am using a book to learn C++. I have noticed that every time that a program is displayed in the book the first lines are:

#include <cstdio> #include <cstdlib> #include < iostream> using namespace std;

what do these lines mean?

also,

how do you know at what point it is allowed to take a function (a chunk of code)?


ghost's Avatar
0 0

Just out of curiosity, what book do you use to learn c++. Because if it doesn't explain that, it must not be a good book ?


ynori7's Avatar
Future Emperor of Earth
0 0

tuchezviper wrote: #include <cstdio> #include <cstdlib> #include < iostream> using namespace std;

what do these lines mean?

The first two, I'm not entirely sure why they need to be included, but they are: cstdio = standard input-output from C cstdlib = standard library of functions from C

The third is the input-output stream which allows you to reference functions for that purpose.

C++ has various namespaces which are groups of functions, identifiers, etc. "using namespace std" just specifies that you are using the std (standard) namespace. If you didn't specify that, then for things such as outputting with cout, you would have to type std::cout instead. It basically tells the program to treat all names from the standard library like they were declared within the program.

how do you know at what point it is allowed to take a function (a chunk of code)? What do you mean?


ghost's Avatar
0 0

inferior wrote: Just out of curiosity, what book do you use to learn c++. Because if it doesn't explain that, it must not be a good book ? Not necessarily, it might be a beginner's book or something similar that prioritizes teaching the basics of variables, input, output, operators, string manipulation, etc. first. This is actually not a bad technique since then one learns the syntax and functionality of what you can do with the simple basic things first and leave the underlying parts, which you won't really get into at the beginning anyway, to later. If the book is a purely beginner's book it might therefor not contain it at all, or alternately contain it later on, but since they don't clearly say "headers" anywhere the person wouldn't know which chapter to look it up at.

tuchezviper wrote: how do you know at what point it is allowed to take a function (a chunk of code)? No idea what you meant by that, clarify.


p4plus2's Avatar
Member
0 0

tuchezviper wrote: how do you know at what point it is allowed to take a function (a chunk of code)? I think he means when do you know you can actually put code? If this is the question then you can place variables in the global scope(just after the area that we see the includes and namespace). For the logic segment of you program it must go in your main function which is set up like this:

int main(int argc, char **argv){
//code here
}

You can also make a custom function but, you always need a main function.

Try to rephrase the question for a better answer.