Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:12:44+00:00 2026-06-04T13:12:44+00:00

My first time working with Visual C++ (new to the language, too) – experienced

  • 0

My first time working with Visual C++ (new to the language, too) – experienced C# …so I have my first console app that I started in Visual Studio.

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int i;

    cin >> i;

    return 0;
}

How come the console window – thus the application – doesn’t close when I press enter? No other input – just enter …

More importantly, how can I make the app exit (don’t want to use exit()) properly if I just hit enter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:12:46+00:00Added an answer on June 4, 2026 at 1:12 pm

    std::cin awaits one non-empty string from you and then tries to convert this string to integer.

    When you press Enter std::cin only gets an empty string and continues to wait for some valid input. This is by design. std::cin is not meant for emulating other interaction.

    To terminate the app on keypress, you have to use OS-specific facilities to read keyboard presses.

    This is the kbhit() function from “conio.h” on DOS/console Windows and the termio functions on POSIX systems.

    From your source I can conclude that you use the MSVC++ compiler, so try replacing

    std::cin >> i
    

    by

    while(!kbhit()) {}
    

    Do not forget to add the

    #include <conio.h>
    

    and remember this is a Windows-specific solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a first time C# project in Visual Studio 2005 and
I've been making my first ASP.NET Visual Studio website and I have just started
I'm working with oracle for the first time, and I have a table called
im working with core-data for the first time, and my app is handling a
I'm working with MVC3 with Razor for first time, and I have a partial
I just started working with dependency injection for the first time and I am
This is my first time that I am working on a big project for
I'm working on my first ThreadPool application in Visual Studio 2008 with C#. I
I am working with Team Foundation Server and Visual Studio 2008 for the first
This is my first time working with file i/o in java, and it's not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.