How do you detect if enter is pressed in C++

How do I detect enter in C++?

I’m using Replit as the IDE, so it should work there.

I think it works the same as python, “”

3 Likes

Following this article, you can do it like so (cross platform):

#include <iostream>
#include <conio.h>
 
int main() {
    char ch;
 
    //program pauses here until key is pressed
    ch = _getch();
 
    if(ch == 'a')
        std::cout << "Key Pressed: a" << std::endl;
    if(ch == 's')
        std::cout << "Key Pressed: s" << std::endl;
    else if(ch == 'A')
        std::cout << "Key Pressed: A" << std::endl;
 
    return 0;
}
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.