【发布时间】:2023-03-25 07:17:01
【问题描述】:
我用 C++ 编写了一个简单的 hello world 程序,以确保它不是导致我遇到困难的编程错误。如果您想检查程序:
#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << "Hello, World\n";
std::cin.ignore();
return 0;
}
无论如何,当我打开几个月前制作的程序时。 (我最近又开始学习了)并运行它应该输出的程序。从头开始创建新程序时,程序会构建并打开一个控制台窗口,但仍处于空白屏幕。我相信这是 IDE 的错,我在某处缺少设置。
新计划:
#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << "Hello, World\n";
std::cin.ignore();
return 0;
}
Ctrl+F5: Blank Console
旧程序:
#include "stdafx.h"
#include <iostream>
int doubleNumber(int x) {
return x * 2;
}
int main()
{
std::cout << "Starting Main" << std::endl;
int y;
std::cout << "Please enter a value you would like to double: ";
std::cin >> y;
y = doubleNumber(y);
std::cout << y << std::endl;
std::cout << "Ending Main" << std::endl;
std::cin.clear();
std::cin.ignore(32767, '\n');
std::cin.get();
return 0;
}
Ctrl+F5: Console as it should be
这个问题在新旧程序的所有情况下都会出现。我今天编写的程序不会向控制台显示任何内容,但我过去编写的程序按预期执行。
【问题讨论】:
-
您使用 Avast 防病毒软件吗?最近有几个问题表明 Avast 导致了这个或类似的问题。
-
我确实这样做了,我禁用了它,它解决了我的问题。谢谢老大。
标签: c++ visual-studio