jeudi 26 octobre 2023

_CRT_RAND_S: How does it working in Windows C/C++?

I wrote code like this:

#include <iostream>
#define _CRT_RAND_S  // may this line cause problem
#include <stdlib.h>


int main(void)
{
    unsigned int r;
    rand_s(&r);

    // ...

    return 0;
}

and compiler said, cannot find rand_s(). Then I switched line 1 and 2, it works.

#define _CRT_RAND_S
#include <iostream>
#include <stdlib.h>
// ...

Question is,

  1. Why do I have to define _CRT_RAND_S at the top of code?
  2. Does <iostream> depends on _CRT_RAND_S? It seems not but...

I tried this in Windows x64, Visual Studio 2022. Thanks.




Aucun commentaire:

Enregistrer un commentaire