jeudi 20 juillet 2017

static_cast doesn't work. C style cast works. How to repair static_cast?

It works fine:

srand(time(NULL));
cout<<(double)rand()/RAND_MAX<<endl;

It doesn't work:

srand(time(NULL));
cout<<static_cast<double>(rand()/RAND_MAX)<<endl;

Why? How to fix it?




Aucun commentaire:

Enregistrer un commentaire