添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I'm trying to figure out how to use vs code, but stupid thing is mad at me.

When I put in this code:

#include <iostream>
using namespace std;
int main()
    cout << "Hello world!";
    int x;
    cin >> x;
    cout << x;
```Nothing happens, it doesn't even get to printing hello world.
When I try this though:
```cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
    for (const string& word : msg)
        cout << word << " ";
    cout << endl;

then it prints the first message, but isn't receiving any data.

What am I doing wrong in vs code (technically Visual Studio Code) and how can I fix it?

Also check that the running program is up to date.

Try to use external console: "console": "externalTerminal",

.vscode

├──launch.json

"configurations": [ "name": "C/C++: cl.exe build and debug active file", "type": "cppvsdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "externalTerminal", "preLaunchTask": "C/C++: cl.exe build active file" "version": "2.0.0"

├──tasks.json

"tasks": [ "type": "cppbuild", "label": "C/C++: cl.exe build active file", "command": "cl.exe", "args": [ "/Zi", "/EHsc", "/nologo", "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", "${file}" "options": { "cwd": "${fileDirname}" "problemMatcher": [ "$msCompile" "group": { "kind": "build", "isDefault": true "detail": "Task generated by Debugger." "version": "2.0.0"

In addition, the original code works well in Visual Studio.

Best regards,

Minxin Yu

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Thank you Minxin Yu!

This does fix the issue with "Hello Wolrd!" not printing, but cin is still not working. Some details to mention: When I first ran the code it was printing in the terminal, now it's printing in the Debug Console. Some people said to find the setting "Run in terminal" however, I could not find that setting.

Thank you again for solving one of two issues!