简体   繁体   English

cout/cin 仅在 VS 代码中无法正常工作

[英]cout/cin not working properly in VS code only

I'm having a problem specifically with VS code where cout and cin are not working in c++ as expected.我在 VS 代码方面遇到了问题,其中 cout 和 cin 无法按预期在 c++ 中工作。

The program is somehow terminating after the first cout and the debugger shows "paused on exception" and then "segmentation fault".该程序在第一个 cout 之后以某种方式终止,并且调试器显示“异常暂停”,然后显示“分段错误”。

Since the same program is running perfectly in Apache Netbeans and other online compilers, I don't think cin.ignore() or endl or anything like that is required.由于相同的程序在 Apache Netbeans 和其他在线编译器中完美运行,我认为不需要 cin.ignore() 或 endl 或类似的东西。

C programs run perfectly fine though (in VS). C 程序运行得非常好(在 VS 中)。

#include <iostream>
using namespace std;

int main() {

    int l,b;
    cout << "\n\nENTER L and B : ";
    cin >> l >> b;
    cout << "L and B entered are : " << l << "\t" << b;    
}

code + output image代码 + output 图像

Here is the debugger screen image这是调试器屏幕图像

Even simple one variable cin statement isn't running and the program is terminating automatically.即使是简单的一个变量 cin 语句也没有运行,程序会自动终止。 cin ain't executing cin没有执行

cout with any variable or constant ain't running correctly either.带有任何变量或常量的 cout 也无法正常运行。

simple cout image简单的 cout 图像

My guess is something's wrong with memory allocation by VS code.我的猜测是 VS 代码分配 memory 有问题。

There seems to ba a problem with your Compiler installation.您的编译器安装似乎有问题。

Consider checking the compiler installation steps from the VS code documentation .考虑检查VS 代码文档中的编译器安装步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM