File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed
Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 11add_library (${CPP_SAFE_IO} STATIC cppsafeio.cpp)
22target_include_directories (${CPP_SAFE_IO} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
3+
4+ if (NOT DEFINED INCLUDE_CONIO_FOR_IO)
5+ option (INCLUDE_CONIO_FOR_IO "Flag for including the conio.h header file" OFF )
6+ endif ()
7+
8+ if (INCLUDE_CONIO_FOR_IO)
9+ message (STATUS "Set flag for including conio.h header file for I/O operations" )
10+ if (NOT WIN32 )
11+ message (FATAL_ERROR "Non-Windows OS detected.\n The conio.h library is not available on other OSs. Terminating..." )
12+ else ()
13+ target_compile_definitions (${CPP_SAFE_IO} PRIVATE INCLUDE_CONIO_FOR_IO)
14+ endif ()
15+ endif ()
Original file line number Diff line number Diff line change 55#include < stdexcept>
66#include < limits>
77
8-
9- #if defined _WIN32
10- // #include <conio.h> //uncomment if your compiler supports conio.h
8+ #if defined(_WIN32) && defined(INCLUDE_CONIO_FOR_IO)
9+ #include < conio.h>
1110#endif
1211
1312void CppSafeIO::clearConsole ()
1413{
15- #if defined _WIN32
14+ #if defined (_WIN32)
15+
16+ #if defined(INCLUDE_CONIO_FOR_IO)
17+
18+ clrsrc ();
1619
17- system (" cls" );
18- // clrsrc(); //uncomment if your compiler supports conio.h, and comment out the previous statement
20+ #else
21+
22+ system (" cls" );
23+
24+ #endif
1925
2026 #elif defined (__LINUX__) || defined(__gnu_linux__) || defined(__linux__)
2127
@@ -40,8 +46,16 @@ void CppSafeIO::ignoreExceedingInput()
4046
4147void CppSafeIO::pressEnterToContinue ()
4248{
43- std::cin.get ();
44- ignoreExceedingInput ();
49+ #if defined(_WIN32) && defined(INCLUDE_CONIO_FOR_IO)
50+
51+ while ( getch () != ' \r ' );
52+
53+ #else
54+
55+ std::cin.get ();
56+ ignoreExceedingInput ();
57+
58+ #endif
4559}
4660
4761bool CppSafeIO::parseYesNoInput (char yesChar, char noChar) {
You can’t perform that action at this time.
0 commit comments