首页 > 解决方案 > 我想换档进入 C++ 但它立即关闭

问题描述

我是 C++ 新手,我遵循 cin 指南,他使用 getline() 函数让程序等到客户端按 Enter 键关闭程序,这对他有用,但在我输入第一个输入后我的程序仍然立即关闭(我不希望用户必须输入一些东西,所以请不要标记为重复!)

#include <iostream>
#include  <filesystem>
#include <string>
using namespace std;
int main()
{
    string santype;
    cout << "What type of sandwhich you want kid?" << endl;
    cin >> santype;
    cout << "Creating " << santype << " Sandwhich" << endl;
    cout << "Press Enter To Exit..";
    getline(cin, santype);
}

标签: c++

解决方案


推荐阅读