+ 3

HOW TO DECLARE A STRUCT IN HEADER FILE C++

I just learned how to use structs but I do not know how to declare a struct in a header class file. #include <iostream> using namespace std; struct coffeeBean { string name; string country; string strength; }; int main(){ coffeeBean newBean; newBean.strength = "9"; newBean.name = "Flora"; newBean.country = "Mexico"; cout << " Coffee Name: " + newBean.name <<endl; cout << "Country: " + newBean.country << endl; cout << "Strength: "+newBean.strength << endl; return 0; }

2nd Jan 2017, 3:50 PM
Baraka Mulungula
Baraka Mulungula - avatar
1 Réponse
+ 1
It's exactly like you wrote it, instead of writing it in the .cpp you write it in the .h file
2nd Jan 2017, 3:59 PM
Amine M. Boulouma
Amine M. Boulouma - avatar