-2

I don't know how to explain it, but I will try.

So I write C++ code and I run it with code runner. But the program closes itself. I don't want to use system("PAUSE"); because I need to remove it if I'm in a competition.

So is there another way?

Denoic
  • 35
  • 1
  • 5
  • Maybe [this answer](https://stackoverflow.com/a/34522206/10077). – Fred Larson May 20 '21 at 20:54
  • @FredLarson nope this doesn't work. I was asking about that when you open an external terminal with the extension to not close itself (the external terminal) right after the code has been runned. – Denoic May 20 '21 at 20:58

2 Answers2

1

Ok, I tried something that came to my mind and it works.

"code-runner.executorMap": {
    "cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start cmd /k $fileNameWithoutExt.exe"
}

I used this in the settings.json

Denoic
  • 35
  • 1
  • 5
1

You can use Dev C++ as an alternative IDE. But if you wish to do it in Visual Studio without a system("PAUSE"); you can use cin.get(); or cin.ignore(); as an alternative.

Code:

#include<iostream>
using namespace std;
int main()
{
    cout << "Hello World";
    cin.ignore();
}

or

#include<iostream>
using namespace std;
int main()
{
    cout << "Hello World";
    cin.get();
}