+ 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; }
1 Respuesta
+ 1
It's exactly like you wrote it, instead of writing it in the .cpp you write it in the .h file