Skip to content

Commit 33e35b8

Browse files
authored
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.
1 parent 1972616 commit 33e35b8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/main/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ int main(int argc, char ** argv) {
450450
std::string line;
451451
bool another_line = true;
452452
do {
453-
std::getline(std::cin, line);
453+
if (!std::getline(std::cin, line)) {
454+
// input stream is bad or EOF received
455+
return 0;
456+
}
454457
if (line.empty() || line.back() != '\\') {
455458
another_line = false;
456459
} else {

0 commit comments

Comments
 (0)