+ 2
Why do i need to include the header #include<string> when its already contained in #include<iostream> header. Below...
#include <iostream> #include <string> using namespace std; class myClass { public: void setName(string x) { name = x; } private: string name; }; int main() { myClass myObj; myObj.setName("John"); return 0; } is it ok even if i exclude the line 2. help
1 Answer
0
You can easily have a situation where <string> is needed without needing <iostream>. You'll often run into headers that include other supporting headers for you. That's why it's common practice to use guard definitions.