Defining a vector breaks program

  c++, g++

I have been coding for quite a few years now, but have only just recently started getting into C++.

I have already made quite a few programs in it, but have recently started running into some odd behaviour. The cases are simple enough that I expect this to be an error with my environment, and not the language itself, but I have run into a dead end.

Consider this simple program:

#include <iostream>
using namespace std;
int main() {
   cout << "Test" << endl;
   return 0;
}

If I compile that and run it, I get, as expected, "Test", in my console.

Now, if I add a vector to it:

#include <iostream>
#include <vector>
using namespace std;
int main() {
   cout << "Test" << endl;
   vector<double> whatever;
   return 0;
}

For some reason, I do not get any output from that.

I have tried initalizing the vector as an empty vector aswell as with predefined values.

I tried adding a for loop running from 0 to 2^32 to see if the program failed entirely, or if it is just the output. This is where things got even weirder.

At first, I placed the loop before defining the vector; that caused the cout to suddenly work again (i.e. "Test" was printed in the console), aswell as stalling the program as expected. I then moved the for loop to after the vector definition, and then it broke entirely; I received no output, and the program exited almost instantly without error.

The issues persist when I remove the using namespace std; and prefix my cout and vector with std::

I use the g++ v6.3 compiler from MinGW. I am running Windows 10.

I am aware that this problem is probably extremely hard to reproduce, but I’ll try my luck here before throwing my computer out the window.

Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT