Просмотр исходного кода

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.
Harald Fernengel 2 лет назад
Родитель
Сommit
33e35b8fe8
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      examples/main/main.cpp

+ 4 - 1
examples/main/main.cpp

@@ -450,7 +450,10 @@ int main(int argc, char ** argv) {
                 std::string line;
                 std::string line;
                 bool another_line = true;
                 bool another_line = true;
                 do {
                 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() != '\\') {
                     if (line.empty() || line.back() != '\\') {
                         another_line = false;
                         another_line = false;
                     } else {
                     } else {