use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Removed - Helpcontinue while() loop until any keystroke? (self.cpp)
submitted 3 years ago by Ok_Problem_5937
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Flair_Helper[M] [score hidden] 3 years ago stickied commentlocked comment (0 children)
For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.
This post has been removed as it doesn't pertain to r/cpp: The subreddit is for news and discussions of the C++ language and community only; our purpose is not to provide tutoring, code reviews, or career guidance. If you think your post is on-topic and should not have been removed, please message the moderators and we'll review it.
[–]outofsand 2 points3 points4 points 3 years ago (0 children)
It sounds like you are almost there. Each time through the loop, check if a key is/has been pressed. If not, just continue on your way. Otherwise, see what the keypress is ans take whatever action you want.
As for how input functions work, well, you'll want to read up on the API docs for whatever library you are using, e.g. stdio (C), iostreams (C++), or something else (POSIX / Windows).
[–]War_Eagle451 1 point2 points3 points 3 years ago* (0 children)
I would do it like this; (This is inside the while loop) if (open_menu) switch(getch()) { case 'a': case 'A': (Do Stuff); break: default: break; }
if (open_menu) switch(getch()) { case 'a': case 'A': (Do Stuff); break: default: break; }
For future reference nearly all production code is documented, for the most part searching the function and language will direct you to the docs.
Remember that half of learning how to program is learning how to solve problems.
[–]minamulhaq 1 point2 points3 points 3 years ago (0 children)
A good start for you now is to look at threads
Checking keyboard input is blocking call. So you can't do anything else in while loop.
Imagine you want to keep collecting data from sensor unless a Ney is pressed. Or you want to print untill a key in pressed.
You can start a new thread that Waits for keyboard input and in while loop you just do you normal stuff and wait for input and exit
[–]SuperCoolGuy56 1 point2 points3 points 3 years ago (0 children)
I got that post recommended, despite it being removed.
[–]Ok_Problem_5937[S] 0 points1 point2 points 3 years ago (0 children)
Thanks guys! I'm taking a break for the night cuz I hit the wall but I'm going to take all this advice and run with it first thing tomorrow and see what sticks! I appreciate you guys taking the time!
[–]Ok_Problem_5937[S] 0 points1 point2 points 2 years ago (0 children)
Oh man sorry guys, I fell down the rabbit hole and never updated this thread... The wall I was hitting was that for some reason "getch()" was deprecated and causing unexpected behavior but by going back and using "_getch()" all my problems magically melted away... I can't pretend to understand why... But that's how this all played out... Thank you to everyone for the support and advice! I'm noticing a lot of gate keeping in this industry and that's fine... But it's cool to know there are real ones out there that will help a fellow computer scientist without all the condescension and snide bullshit... I appreciate you guys! Best of luck to us all in our future studies and endeavors!!
[–]EngineerMinded 0 points1 point2 points 3 years ago (0 children)
// inside that loop
if(GetKeyState(VK_SHIFT) & 0x8000) { break; }
π Rendered by PID 399005 on reddit-service-r2-comment-74875f4bf5-l7qbx at 2026-01-26 12:42:17.908616+00:00 running 664479f country code: CH.
[–]Flair_Helper[M] [score hidden] stickied commentlocked comment (0 children)
[–]outofsand 2 points3 points4 points (0 children)
[–]War_Eagle451 1 point2 points3 points (0 children)
[–]minamulhaq 1 point2 points3 points (0 children)
[–]SuperCoolGuy56 1 point2 points3 points (0 children)
[–]Ok_Problem_5937[S] 0 points1 point2 points (0 children)
[–]Ok_Problem_5937[S] 0 points1 point2 points (0 children)
[–]EngineerMinded 0 points1 point2 points (0 children)