Looking for a firm understanding of different lines

I've been doing well on my program writing so far but I have a question as to how to understand what I'm writing. I have a firm understanding on variables, writing equations, ect but I want to know what these specific lines do to a program and what they allow me to do.

1
2
3
4
5
6
7
8
9
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()


What does each one do? I am also really curious what exactly int main() does... I am in my first programming course and just scrolling through my book I have seen int main(void) used as well... not 100% sure what that means.

Anyone care to explain? Thank You.
You can check what each header contains in the reference on this site:
http://www.cplusplus.com/reference/

using namespace std; allows you to use names in the std namespace without fully qualifying them.
Everything in the standard library is in the namespace "std". So with the using directive, you can write fstream instead of std::fstream, cout instead of std::cout etc. Namespaces are used for organization and to avoid name clashes in different libraries.

int main() is the prototype of a function called main that returns an int and takes no parameters. int main(void) means exactly the same. There used to be a difference in C, but this is not the case in C++.
main is a special function because it is automatically called when your program starts.
Last edited on
Thank You.
Topic archived. No new replies allowed.