0
#include <iostream>
using namespace std;

int main()
{
    char buf[20];
    cin.ignore(7);
    cin.getline(buf,10);
    std::cout << buf << endl;
    return 0;
}

Above is my code. From the console window, we can input a text as "I like hiking" and press enter, however, the console window disappears.

FortranFun
  • 156
  • 1
  • 11
  • Also duplicate of [Preventing console window from closing on Visual Studio C/C++ Console application](https://stackoverflow.com/questions/1775865/preventing-console-window-from-closing-on-visual-studio-c-c-console-applicatio) – Patrick Roberts May 22 '17 at 23:43

1 Answers1

2

This is happening because you are returning before you are able to see the output. (the computer is going faster than your eyes can see the output)

For debugging purposes, you can put

system("pause");

before the return statement in order to see the output. (this will provide a "Please press any key to continue..." prompt to you to tell the program to continue after you've hit a key

ddavison
  • 28,221
  • 15
  • 85
  • 110