Why we don't use string header file in this snippet | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why we don't use string header file in this snippet

#include <iostream> using namespace std; class Birthday { public: Birthday(int m, int d, int y) : month(m), day(d), year(y) { } void printDate() { cout<<month<<"/"<<day <<"/"<<year<<endl; } private: int month; int day; int year; }; class Person { public: Person(string n, Birthday b) : name(n), bd(b) { } void printInfo() { cout << name << endl; bd

8th Aug 2017, 6:22 AM
Rahul.R
Rahul.R - avatar
1 Answer
+ 8
In some compilers, <string> is included in <iostream>. That said, it is a good practice to explicitly include <string> when you need to utilize the string class.
8th Aug 2017, 12:55 PM
Hatsy Rei
Hatsy Rei - avatar