jeudi 26 novembre 2020

what needs doing if including cstdlib doesn't let me use rand()?

So, I'm trying to replicate a simple dice roll using cstdlib and rand(), but visual studio code seems to have a problem with rand, claiming it's not defined, despite me having included cstdlib, any thoughts?

i'll paste the code, as bare bones as it is atm, perhaps someone could figure it out? FYI, I'm using Visual Studio Code on PopOS 20.10 (not sure if it's relevant)

#include <iostream>
#include <cstdlib>
#include <random>

class player
    {
        public:

            std::string name;
            int health;
            int strength = 1 + (std::rand() % 12);
            int defense;
            int initiative;
            int luck;

            void levelup();

            void win();

            void lose();

        private:   

    };

The error it throws up is: namespace "std" has no member "rand" C/C++(135)




Aucun commentaire:

Enregistrer un commentaire