Using MinGW GCC 4.6.2, I found that my code still compiles if I don't have std:: in front of some of the functions (specifically, it seems, the ones that are also part of the C library).
For instance, this compiles and runs with no errors or warnings:
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
int main()
{
// No std:: on any of these
clock_t start = clock();
double blah = sqrt(4.0);
srand(time(0));
int random = rand();
double blahy = log10(10.0);
double log10; // This works (as I would expect)
//log10 = log10(100.0); // Error if I uncomment (as I would expect)
log10 = std::log10(100.0); // NOW I have to use std::
// Yes, I know this is C++, not C, but this is just to show that this works without std::
printf("%ld\n%f\n%d\n%f\n%f\n", start, blah, random, blahy, log10);
system("pause"); // Ewww, system()...
return 0;
}
This also compiles (as expected) if I stick std:: in front of everything (well, not everything, of course, but you get the point).
Was that supposed to compile?
It looks you have pretty much a C based program there. I believe clock_t is C++ based so you might need a std:: namespace in front of that but everything else looks like C code.
Why don't you make things easy on yourself and just add:
usingnamespace std;
before your code.
That way you don't have to scope the std:: namespace every time you need to use it.
Edit: printf is more C than C++. C++ uses cout as the standout output.
C is really powerful but it's also weird. Pretty much everything is treated like a file and it allows you more control which also leads to more mistakes so I would try to learn C++ instead.
The standard doesn't require, but also doesn't forbid <cstdio>, <cstdlib>, and <ctime> to place symbols in both the std namespace and the global namespace (where <stdio.h>, <stdlib.h> and <time.h> would put them).
So, many compilers (or, technically, standard library implementations) do both. But to be totally portable, you need std:: in front of every standard library symbol in that program.
If one wasn't worried about portability, it seems like one wouldn't ask the question. After all, if you're not worried about what's portable and what's not you can just go with whatever works on your compiler without a care for whether it should or shouldn't work that way.
Btw, whether printf is "more C than C++" doesn't really matter. It is C++. (And in many cases the C-oriented i/o functions are more efficient than C++ counterparts, meaning there is plenty of reason to use them in scenarios where i/o performance is paramount.)