[英]Simple cin cout Code runs by “build and run” but dosent work from bin/debug/x.exe
我是编码新手。 我只是通过使用代码块制作了这个简单的代码。 它可以从“构建并运行”选项中完美地工作,但是在运行“ .exe”文件时,它会关闭而不是在输入值时不起作用。
我已经两次安装了代码块,但仍然无法正常工作。
#include <iostream>
using namespace std;
int main()
{
int no;
cout << "Type the number u need the square of" << endl;
cin >> no;
cout << " The square of " << no << " is " << no*no << endl;
return 0;
}
您可以让应用程序等到输入关闭为止。 在代码末尾添加两行:
std::cout << "Press enter to quit.\n";
std::cin.ignore();
如果您通过单击.exe直接运行它,则程序将在完成后立即关闭。 这也将关闭终端窗口。
如果您直接从终端运行程序,则不会发生(因此请在终端内部启动它,而不是单击.exe)。
或者,您可以让它在打印值之后但退出之前等待用户输入。 这将使您有机会了解其价值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.