<cstdlib> or <stdlib.h>

Hey Thanks for helping me out here. I seem to have found this small bit of code thats been bugging me, sorry for the pun. Anyways on line 3 I can either use < <cstdlib> or <stdlib.h> . What is the difference and also what does the h stand for I believe it's header but not for sure on this one. Sorry if this has already been posted I couldn't find it. If it already has if you could link me to it that would be amazing. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <math.h>
#include <cstdlib> // Or should I use this? ---> #include <stdlib.h>
#include <time.h>

int rand_0toN1(int i);

int main()
{
    int n, i;
    int r;

    srand(time(0)); // set a seed for random-num
                    //generation
    std::cout << "Enter number of dice to roll: ";
    std::cin >> n;

        for(i = 1; i <= n; i++)
        {
            r = rand_0toN1(6) + 1;  //get number from 1 to 6;
            std::cout << r << " "; //print out

        }
        return 0;
}

int rand_0toN1(int n)
{
    return rand() % n;
}
C header files have a .h extension, C++ header files either have .hpp or nothing at all.
closed account (jwkNwA7f)
What Computergeek01 said.
Like these:
C------------------>C++
stdlib.h----------->cstlib
string.h----------->cstring
time.h------------->ctime
stdio.h------------>cstdio
etc.
Last edited on
Thanks I wondered why they had a h. Guess I better redo that little doodad.
Thanks again I didn't even find that part of the site I feel stupid now hehe. The info is great.
Topic archived. No new replies allowed.