Home > other >  Nothing execute when using Vector in C with VSCode
Nothing execute when using Vector in C with VSCode

Time:06-24

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:

#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 progam -Wall main.cpp
When I run this on the "Terminal" of Visual Studio Code it doesn't works. But when I rut it on another shell it works.

CodePudding user response:

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.

  • Related