1
#include<iostream>

int main() {

std::string str = "Hello";

std::cout << str << std::endl;

return 0;

}

As I learned from various places, whenever you want to use std::string you should include string header file.

However, the code above does not require #include<string> to run, why is that so?

note: I am using g++ to compile it from bash terminal.

muyustan
  • 1,303
  • 1
  • 6
  • 21
  • 5
    In your case, `` apparently includes ``. It is not guaranteed to work across other compilers. – Ardent Coder Apr 05 '20 at 17:05
  • 2
    Does this answer your question? [Can std::string be used without #include ?](https://stackoverflow.com/questions/33349833/can-stdstring-be-used-without-include-string) – Brian Apr 05 '20 at 17:05
  • @Brian yes, thanks, I could not find it while I searched. – muyustan Apr 05 '20 at 17:31

0 Answers0