formulahendry / formulahendry/vscode-code-runner

[Bug] code runner "Run in Terminal" with bad naming C++ file couldn't output right results

Open
#1,162 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.4k
Forks
351
PR merge metrics
No merged PRs in 30d

Description

- VS Code Version: 1.91.1
- OS Version: Windows 11, 22631
- Code Runner Version: 0.12.2

**Describe the bug**
When code runner setting "Run in Terminal" set to True, bad naming C++ files (4.2.3.instr2.cpp for example) couldn't output correct results in terminal.

**To Reproduce**
Steps to reproduce the behavior:

1. Set "Run in Terminal" of code-runner to "True"
2. Create a C++ file with bad naming, for example "4.2.3.instr2.cpp"
3. Edit the C++ file, with input and output using `cout` and `cin`, for example:
```c++
// instr2.cpp -- reading more than one word with getline
#include
int main()
{
using namespace std;

const int ArSize = 20;
char name[ArSize];
char dessert[ArSize];

cout << "Enter your name:\n";
cin.getline(name, ArSize);
cout << "Enter your favorite dessert:\n";
cin.getline(dessert, ArSize);
cout << "I have some delicious " << dessert;
cout << " for you, " << name << ".\n";

return 0;
}
```
4. Run code with Ctrl+Alt+N

**Actual behavior**
The terminal outputs:
```powershell
PS G:\OneDrive\Obsidian\06-Coding\C++\cppPrimerPlus\chapter.4.compoTypes\4.3.stringClass> cd "g:\OneDrive\Obsidian\06-Coding\C++\cppPrimerPlus\chapter.4.compoTypes\4.2.strings\" ; if ($?) { g++ 4.2.3.instr2.cpp -o 4.2.3.instr2 } ; if ($?) { .\4.2.3.instr2 }
PS G:\OneDrive\Obsidian\06-Coding\C++\cppPrimerPlus\chapter.4.compoTypes\4.2.strings>
```

**Expected behavior**
```powershell
PS G:\OneDrive\Obsidian\06-Coding\C++\cppPrimerPlus\chapter.4.compoTypes\4.3.stringClass> cd "g:\OneDrive\Obsidian\06-Coding\C++\cppPrimerPlus\chapter.4.compoTypes\4.2.strings\" ; if ($?) { g++ 4.2.3.instr2.cpp -o 4.2.3.instr2 } ; if ($?) { .\4.2.3.instr2 }
Enter your name:
```

**Screenshots**

![QQ20240730-122442](https://github.com/user-attachments/assets/57c9335f-2183-476f-abce-2419c4139a74)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.