问题描述
我有一些包含各种 std::cout 输出的 C++ 可执行文件。 在 Visual Studio 2019 x64 Native Tools Command Prompt 中,当我运行这些可执行文件时,控制台上没有显示任何输出。 如果我将输出重定向到文件,则输出确实会打印到文件中。
#include <iostream>
int main (int argc,char** argv) {
std::cout << "Hello world" << std::endl;
}
是否需要设置一些设置或变量才能在控制台本身中查看输出?
解决方法
根据你提供的代码,我的控制台程序可以正常输出。
我建议您可以验证是否正确设置了 Visual C++ 开发人员命令提示符。在命令提示符窗口中,输入 cl
并验证输出是否如下所示:
有关如何在命令行上编译 Native C++ 程序的更多详细信息,建议您可以参考文档:Walkthrough: Compiling a Native C++ Program on the Command Line