1

Im new to C++ and im following a guide on cin he used a getline() function for the program to wait until the client presses enter to close the program, it works for him, but my program still instantly closes after i put the first input in. (I DO NOT WANT THE USER TO HAVE TO TYPE SOMETHING SO PLEASE DO NOT MARK AS A DUPLICATE!)

#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);
}
Plieax
  • 19
  • 3
  • 1
    +1 simply for having a [mcve], and for only writing a few lines of code rather than typing out your entire program before compiling it. Btw it's spelled "sandwich" – Tas Jan 03 '19 at 02:45
  • This question is already closed. The duplicate explains how to fix the getline() so that the program waits for enter to be pressed before closing. – drescherjm Jan 03 '19 at 04:49

0 Answers0