Home >Backend Development >C++ >How Can I Provide Standard Input to My C/C Program When Debugging in Visual Studio Code?
Writing to Standard Input in Visual Studio Code with C/C Extension
Debugging a C/C program often requires the ability to provide user input during execution. This can be challenging when using the C/C extension in Visual Studio Code, especially for Windows users since the debugging facility is unavailable.
Current Implementation:
You have successfully configured Visual Studio Code to build and run your code using a Makefile and custom tasks. However, to receive user input at runtime, you need to enable console input.
Solution:
{ "code-runner.runInTerminal": true }
Explanation:
The code-runner.runInTerminal setting launches the program in the integrated terminal. This allows for standard input while the program is running.
Example:
Consider the following helloworld.cpp program:
#include <iostream> using namespace std; int main() { string name; cout << "Enter your name: "; cin >> name; cout << "Hello, " << name << "!!!" << endl; return 0; }
When you run this program with the modified settings, the terminal will prompt you for input and pass it to the program as standard input.
The above is the detailed content of How Can I Provide Standard Input to My C/C Program When Debugging in Visual Studio Code?. For more information, please follow other related articles on the PHP Chinese website!