vscode-code-runner icon indicating copy to clipboard operation
vscode-code-runner copied to clipboard

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

Open FlyingWing12138 opened this issue 1 year ago • 2 comments

  • 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:
// instr2.cpp -- reading more than one word with getline
#include <iostream>
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;
}
  1. Run code with Ctrl+Alt+N

Actual behavior The terminal outputs:

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

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

FlyingWing12138 avatar Jul 30 '24 04:07 FlyingWing12138

Removing "." in file name (for example, change "4.2.3.instr2.cpp" to "instr2.cpp" could solve the problem.

FlyingWing12138 avatar Jul 30 '24 04:07 FlyingWing12138

can you show your executor map line for c++?

looks like either an issue with quoting or the .\

ericchase avatar Oct 17 '25 12:10 ericchase