At the time you call v[0], the vector has zero size, so you are accessing out of bounds. This is undefined behaviour.
Furthermore, std::vector<bool> is a specialization which has strange behaviour due to the fact that it does not hold individual bool elements. Its operator[] returns a kind of proxy object, the call to that operator may not do what you expect. It should be used with care, or not used at all.
You can solve the problem by reading a value into a local variable and then pushing it into the back of the vector, as in this working example (similar live demo here):
#include <vector> #include <iostream> int main() { std::vector<bool> v; std::cout << std::boolalpha; v.push_back(true); std::cout << v[0] << std::endl; bool b; cin >> b; v[0] = b; std::cout << v[0] << std::endl; }