Why do i need to include the header #include<string> when its already contained in #include<iostream> header. Below... | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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

20th Jul 2017, 8:20 AM
stephen haokip
stephen haokip - avatar
1 Respuesta
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.
21st Jul 2017, 3:13 AM
Greg Bodnar
Greg Bodnar - avatar