0
#include<iostream>
#include<vector>

int main() {
   
    std::vector<int> score = {1, 2, 3, 4};

    std::cout << score.size() << std::endl;
    
}

When I compile with "g++ filename.cpp" and then run "./a.exe" the terminal is empty my terminal

  • 1
    Try `std::cout << score.size() << "\n";` – Retired Ninja Aug 21 '22 at 03:25
  • Refer to [how to ask](https://stackoverflow.com/help/how-to-ask) where the first step is to *"search and then research"* and you'll find plenty of related SO questions. – Jason Aug 21 '22 at 03:29
  • @JasonLiam I haven't found anything for what I posted. I searched for 2 hours on how to print vectors in c++. It gets harder since there is no error in vscode or when compiling. – Brandon Chan Aug 21 '22 at 06:44
  • @RetiredNinja sadly that doesn't work. I have tried adding spaces, newlines, etc. I also tried a different wait of iteration like `for (int i: score)`. It just won't print. – Brandon Chan Aug 21 '22 at 06:45
  • @BrandonChan Did you try: `std::cout < – Jason Aug 21 '22 at 06:53
  • @JasonLiam This doesn't change the outcome, and the dupe doesn't answer the question. (Most of the answers there are just plain wrong). The correct answer is *MinGW doesn't work, change your compiler*. – n. m. could be an AI Aug 21 '22 at 16:44
  • @n.1.8e9-where's-my-sharem. is there a reason that it's the compiler shown in the vscode tutorial on how to use c++? What would you suggest I install or change? – Brandon Chan Aug 21 '22 at 21:34
  • Install MSYS2 https://www.msys2.org/ then from within msys2 shell install gcc `pacman -S base-devel gcc`. – n. m. could be an AI Aug 22 '22 at 03:36
  • @n.1.8e9-where's-my-sharem. That's what I've installed. I have run that command in the MSYS2 console. I guess I will try to reinstall MSYS2. – Brandon Chan Aug 22 '22 at 04:26
  • You installed gcc or mingw from the msys2 console? I see you are in the mingw console. – n. m. could be an AI Aug 22 '22 at 04:34
  • @n.1.8e9-where's-my-sharem. I've installed both? I don't know how to answer that. I followed all the steps from MSYS2's website, steps 1-8. And I don't know why MINGW64 is there as I'm using git bash as my terminal. It probably has something to do with adding it to my path environment – Brandon Chan Aug 22 '22 at 04:38
  • Let me check my own installation – n. m. could be an AI Aug 22 '22 at 04:39
  • Type `which gcc` from your git bash prompt, what do you see? – n. m. could be an AI Aug 22 '22 at 04:43
  • @n.1.8e9-where's-my-sharem. Thank you so much for helping me out here. I am just trying to get this all sorted out before school starts up again. – Brandon Chan Aug 22 '22 at 04:43
  • @n.1.8e9-where's-my-sharem. "/c/msys64/mingw64/bin/gcc" is what I get. I should also ask isn't gcc used to compile C and not C++? Every time I try to compile with gcc I get errors and from other threads I've seen I should use g++ for C++. – Brandon Chan Aug 22 '22 at 04:45
  • Yes you should compile and link c++ code with g++. I just wanted to see how your path is set up. It is strange because this setup works for me just fine. Anyway try the same commands from the msys2 mingw64 console and from msys2 console (these are a bit different things) – n. m. could be an AI Aug 22 '22 at 04:57
  • @n.1.8e9-where's-my-sharem. Okay, wow. I have tried using the MSYS2 console before and the commands didn't work. I didn't know the mingw64 console was a thing and running my a.exe in there works as expected. This basically solves my issue. I will just make this my default terminal in vscode. Do you have a clue as to why though this wouldn't work in my git bash terminal? – Brandon Chan Aug 22 '22 at 05:03
  • No, I don't know. I've had troubles with mingw64 in the past, where either the compiler itself or the compiled program just would terminate on startup without any error message. – n. m. could be an AI Aug 22 '22 at 05:09
  • Well, for right now this temporary solution works and I really appreciate the responses. – Brandon Chan Aug 22 '22 at 05:15
  • @n.1.8e9-where's-my-sharem. I updated git bash. And it works. – Brandon Chan Aug 22 '22 at 05:23

1 Answers1

0

I have figured out the issue and a solution. I updated git bash to the latest version and it now prints properly to my git bash terminal. Thank you to everyone who took the time to type out a response and try to help, I really appreciate it all.