Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Nothing execute when using Vector in C++ with VSCode

The problem

I have a problem with Vector in C++.
When I try to do basic things with them, my program "doesn’t works" anymore

What I tried

Searching on Stack Overflow but didn’t find something relevent.
But I don’t know a lot on this topic so I’m kind of stuck with it.

Some code:

Example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream>
#include <vector>

int main(int argc, char ** argv){
    std::cout << "Hello world\n";
    std::vector< int > arr;
}

This program will outputs "Hello world" because I don’t interact with the vector.
But if I do:

#include <iostream>
#include <vector>

int main(int argc, char ** argv){
    std::cout << "Hello world\n";
    std::vector< int > arr;
    arr.push_back(1);

}

for example, there is no STDOUT. Hello world is never "printed". And there is no errors.
I’m on Visual Stduio code and I compile my program with
g++ -o -Wall main.cpp

>Solution :

The command g++ -o -Wall main.cpp will create an executable file called -Wall. Unless that’s the program you’re trying to run, it’s not going to work.

Instead you would need something like g++ -o program -Wall main.cpp and then run program. Both of your examples do the right thing in that case.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading