c++ - 如何在第一次输入后立即停止 C++ 控制台关闭

标签 c++ visual-studio visual-studio-2013 console

<分区>

我最近决定开始学习 C++,一开始我遇到了控制台在输出后立即关闭的问题,这可以通过添加 System("pause") 来解决,现在我有一个程序两个输入,在第一次输入后控制台关闭,没有显示任何输出,我无法用系统(“暂停”)修复它。

#include <iostream>
using namespace std;

int main(){
    char name[50];
    int age;

    cout << "Please enter your name? ";
    cin >> name;


    cout << endl << "Okay, how old are you ? ";
    cin >> age;

    cout << "Nice to meet you, " << name << "!" endl;

    if (age < 10) cout << "Oh, you're quite young aren't you!" << endl; else
        if (age < 20) cout << "Embrace your teens they won't last long!" << endl else
            if (age < 40) cout << "Ah, I see you're still in your prime" << endl else
                if (age < 60) cout << "That's nice" << endl;


    return 0;
}

最佳答案

在 Visual Studio 中,通过 Ctrl+F5 运行您的程序。

关于c++ - 如何在第一次输入后立即停止 C++ 控制台关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27575428/

相关文章:

c# - 将数据绑定(bind)到 Windows Phone 中的可观察集合

c# - DefaultTraceListener 不起作用

visual-studio - 为什么我在下载 FontAwesome nuget 包后看不到文件?

tfs - Visual Studio 2013 Pro 可以连接到 Team Foundation Server 2010 吗?

visual-studio - TFS 2013 + GIT, checkin 政策

visual-studio - Visual Studio 无法检索服务 'Microsoft.VisualStudio.WindowsAzure.Authentication.IAzureRMTenantService'

c++ - SDL 混合导致不正确的帧插值

c++ - 我真的应该将头文件指定为 target_sources() 吗?

c++ - 创建顶点缓冲区 DirectX11 时出错

c++ - 使用 C++ 库