I’m trying to get more experienced in C++ and I kinda just wanna know how I can add a structure to an array with it’s default values
Here is a very basic example of initializing a Struct with default values. The thing to keep in mind is that you need a constructor that sets all default values. Structs are pretty much the same as Classes, the main difference is that for Classes; members and base classes are private by default in classes but are public by default in structs.
// Example program
#include <iostream>
#include <string>
struct myStruct
{
int structInt1, structInt2;
myStruct()
{
structInt1 = 1;
structInt2 = 2;
};
};
int main()
{
using namespace std;
//creates an Array of Ten structs with default values from the constructor
myStruct myStructArray[10]{};
for (myStruct x : myStructArray)
cout << x.structInt1 << x.structInt2 << endl;
};