aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Fernengel <harald.fernengel@here.com>2023-03-26 07:25:46 +0200
committerGitHub <noreply@github.com>2023-03-26 08:25:46 +0300
commit33e35b8fe8f09adcac0632e9cece62e1dd629f7d (patch)
tree70c6a0731dbd08f458e8ab775f3b589f3e708484
parent19726169b379bebc96189673a19b89ab1d307659 (diff)
Exit from interactive mode if input stream is bad (#491)
Allow exiting the interactive prompt also with CTRL-D on Unix and CTRL-Z on Windows.
-rw-r--r--examples/main/main.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/main/main.cpp b/examples/main/main.cpp
index 9af8a74..e9478d5 100644
--- a/examples/main/main.cpp
+++ b/examples/main/main.cpp
@@ -450,7 +450,10 @@ int main(int argc, char ** argv) {
std::string line;
bool another_line = true;
do {
- std::getline(std::cin, line);
+ if (!std::getline(std::cin, line)) {
+ // input stream is bad or EOF received
+ return 0;
+ }
if (line.empty() || line.back() != '\\') {
another_line = false;
} else {