-1

I've just started coding in C++ with VSCode and I followed the setup here. It works perfectly with the coderunner extension in the terminal, however I am unable to use std::cin inside of a for loop. I can use it on a fixed number of times, like:

int x;
cin >> x;

but as soon as I use dynamic input, like

int x = 5;
vector<long long> a(x);
for (int i = 0; i < x; i++)
{
    cin >> a[i]; 
}

my program stops working. Originally the terminal would look like this, indicating the program is running and awaiting input

enter image description here

but while using a loop the program looks like thisenter image description here and input does not work.

My settings.json file looks like this:

{
"C_Cpp.errorSquiggles": "Enabled",
"code-runner.runInTerminal" : true,

"files.associations": {
    "iostream": "cpp",
    "vector": "cpp",
    "algorithm": "cpp",
    "chrono": "cpp",
    "complex": "cpp",
    "cstdlib": "cpp",
    "valarray": "cpp"
}

and my c_cpp_properties.json like this:

{
"configurations": [
    {
        "name": "Win64",
        "includePath": [
            "${workspaceFolder}/**",
            "${workspaceFolder}"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "windowsSdkVersion": "10.0.19041.0",
        "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe",
        "cStandard": "c17",
        "cppStandard": "c++17",
        "intelliSenseMode": "windows-msvc-x64"
    }
],
"version": 4
}

The extensions I have installed are: Better C++ Syntax, C/C++, C/C++ Compile Run, C/C++ Extension Pack, C/C++ Themes, CMake, and CMake Tools

Any help would be greatly appreciated!!

OmikronII
  • 33
  • 6
  • It just abruptly ends, I'll the question with some photos – OmikronII May 08 '22 at 19:57
  • 1
    Voting to close as not enough information to [reproduce](https://godbolt.org/z/j96nGnK3f). For us to help we need to see ALL relevant code, and as it stands the issue does not seem to be caused by code provided. Maybe [`using namespace std;`](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) can be a culprit? – Lala5th May 08 '22 at 19:59
  • I tried the namespace and It didn't fix it, I also don't think the code is the issue. I think it's either that I suck at using VSCode or something is wrong with how I set it up. I want to be able to copy and paste my input into the terminal like I would with java/python but that isn't working for some reason. – OmikronII May 08 '22 at 20:04

0 Answers0