manipulation of any one struct

-2

I have a struct, how do I predefine data in this struct? example define life of struct 100?

I've tried dataplyer.vida = 100;

struct dataplayer
{
    int vida;
    int armadura;
    int arma;
    int level;
};
    
asked by anonymous 05.01.2019 / 05:10

1 answer

0

The problem must be in another area of the code, apparently you seem to be correctly setting the attribute. So, I suppose your problem is another, but, answering the question, just use the "." (dot) to access the element you need and the assignment operator "=" to assign the value.

Of course, you need to create a "variable" to assign the actual value of a player to memory, in my case p1.

Here's an example:

#include <iostream>

using namespace std;

struct dataplayer { int vida; int armadura; int arma; int level; };

int main()
{
    cout<<"definindo a vida \n";

    //seu player
    dataplayer p1;

    p1.vida = 100;

    cout << p1.vida;

    return 0;
}

You can test this code here:

link

Note: It also was not clear to me, and I'm sleepy, if you encode in c or c ++, I recommend you choose one.

    
05.01.2019 / 05:34