Why don't you have to include < vector > if you already include using
namespace std
Take a look at this url: https://en.cppreference.com/w/cpp/header
There are more than 100 header files available for your use.
IMHO, the confusion you are experiencing is that these same 100+ header are ALSO available for the header authors, and they also have access to headers not usually published in the standard. The result is that, for instance, when you or I include < stringstream >, some indirect part of that include might also 'pull-in' < string >.
I recommend you do not put "using namespace std" in your code. It's use did not intentionally cause the 'hidden / indirect' include of < vector >, and maybe won't on the next implementation.
I'm on g++v7.3. I'll soon be upgrading to current g++ (I think 9.x?) You can not rely on < vector > being included unless you explicitly include it.
this works for me, but I want to understand why this one works and the
other one doesn't.
Just luck ... I think bad, if you start multiple bad habits because of it.
If your compiler supports -std=c++17 or better, it has a new feature I like. The new feature allows me to, immediately after the header include, specify which function in that library I specifically need. It looks like this:
#include <iostream>
using std::cout, std::cerr, std::endl, std::flush,
std::hex, std::dec, std::cin;
#include <iomanip>
using std::setw, std::setfill;
#include <string>
using std::string, std::to_string;
#include <thread>
using std::thread, std::this_thread::sleep_for;
#include <vector>
using std::vector;
Your own libraries can be handled similarly:
#ifndef DTB_ENG_FORMAT_HH
#include "../../bag/src/dtb_eng_format.hh"
using DTB::EngFormat_t;
#endif
#ifndef DTB_PPLSEM_HH
#include "../../bag/src/dtb_pplsem.hh"
using DTB::PPLSem_t;
#endif
#ifndef DTB_ENG_FORMAT_HH
#include "../../bag/src/dtb_eng_format.hh"
#endif
#ifndef DTB_ASSERT_HH
#include "../../bag/src/dtb_assert.hh"
#endif
I try to keep track of a smalle set of these, and collect them in a file. I use the bigger lists when I am starting a new effort, and trivially remove the 'unused' functions (when I want to post my efforts).