struct arrays
Hello again, all!
I'm trying to stick an array of structs into a vector. I'm assuming this is possible? Here's my code so far:
#include
#include
using std::vector; using std::cout;
using std::endl; using std::cin;
using std::string;
struct Card {
int value;
string suit;
};
vector stack_deck(struct Card& card, vector& c_stack)
{
for (int i = 0; i != c_stack.size(); ++i) {
c_stack.push_back(card.value);
}
return c_stack;
}
int main()
{
return 0;
}
Which obviously makes no use of arrays.... And only allows one value from the struct to be put on the end of the vector. So, two problems to solve:
1. How do I put multiple values on the vector for the same entry? Is it just a case of making it vector ? Or do I have to use more than one vector?
2. How do I put structs within an array? Is this possible?
Thanks in advance.
I'm trying to stick an array of structs into a vector. I'm assuming this is possible? Here's my code so far:
#include
#include
using std::vector; using std::cout;
using std::endl; using std::cin;
using std::string;
struct Card {
int value;
string suit;
};
vector
{
for (int i = 0; i != c_stack.size(); ++i) {
c_stack.push_back(card.value);
}
return c_stack;
}
int main()
{
return 0;
}
Which obviously makes no use of arrays.... And only allows one value from the struct to be put on the end of the vector. So, two problems to solve:
1. How do I put multiple values on the vector for the same entry? Is it just a case of making it vector
2. How do I put structs within an array? Is this possible?
Thanks in advance.
