EnderstevePL Temat założony przez niniejszego użytkownika |
"Zacinanie się programu" [C++] » 2018-10-07 17:19:18 Generalnie napisałem funkcję (próbuje zrobić coś w rodzaju scanf i printf ale na własne potrzeby, nie pytajcie czemu) i polecenia sa wykonywane do pewnego momentu, który oznaczyłem, po czym program się kończy. Nie mam pojęcia jak to naprawić. Kod źródłowy: Plik konsola.cpp #include "konsola.hpp" #include <conio.h> #include <windows.h> #include <stdlib.h> #include <iostream>
std::vector < std::string > text_history; std::vector < char > color_history; std::vector < bool > color_intensive_history;
int consol::command_list( std::string input ) { if( input == "start" ) return 0; else if( input == "kill" ) return 1; else if( input == "open" ) return 2; else if( input == "close" ) return 3; else if( input == "connect" ) return 4; else if( input == "disconnect" ) return 5; else if( input == "enter" ) return 6; else if( input == "back" ) return 7; else if( input == "list" ) return 8; }
void consol::time_writing( std::string text, char color, int delay, bool color_intensive, bool skip_space, bool add_history ) { HANDLE hOut; hOut = GetStdHandle( STD_OUTPUT_HANDLE ); if( color != 'w' ) { if( color_intensive == false ) { switch( color ) { case 'r': SetConsoleTextAttribute( hOut, FOREGROUND_RED ); break; case 'g': SetConsoleTextAttribute( hOut, FOREGROUND_GREEN ); break; case 'b': SetConsoleTextAttribute( hOut, FOREGROUND_RED ); break; case 'p': SetConsoleTextAttribute( hOut, FOREGROUND_RED | FOREGROUND_BLUE ); break; case 'y': SetConsoleTextAttribute( hOut, FOREGROUND_RED | FOREGROUND_GREEN ); break; case 'c': SetConsoleTextAttribute( hOut, FOREGROUND_GREEN | FOREGROUND_BLUE ); break; } } else { switch( color ) { case 'r': SetConsoleTextAttribute( hOut, FOREGROUND_RED | FOREGROUND_INTENSITY ); break; case 'g': SetConsoleTextAttribute( hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY ); break; case 'b': SetConsoleTextAttribute( hOut, FOREGROUND_RED | FOREGROUND_INTENSITY ); break; case 'p': SetConsoleTextAttribute( hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); break; case 'y': SetConsoleTextAttribute( hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY ); break; case 'c': SetConsoleTextAttribute( hOut, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); break; } } } for( int unsigned i = 0; i <= text.size() - 1; i++ ) { std::cout << text[ i ]; if( text[ i + 1 ] != ' ' ) Sleep( delay ); else if( skip_space == false ) Sleep( delay ); } if( add_history == true ) { text_history.push_back( text ); color_history.push_back( color ); color_intensive_history.push_back( color_intensive ); } SetConsoleTextAttribute( hOut, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED ); }
void consol::enter_text( std::string ae_text, char ae_color, bool ae_intensive, char enter_color, bool enter_intensive ) { std::string entering_text = "blabla"; int first_char; int second_char; do { system( "cls" ); for( int unsigned i = 0; i <= text_history.size() - 1; i++ ) { time_writing( text_history[ i ], color_history[ i ], 0, color_intensive_history[ i ], true, false ); } time_writing( ae_text, ae_color, 0, ae_intensive, true, false ); time_writing( entering_text, enter_color, 0, enter_intensive, true, false ); } while( getch() != 13 ); entering_text += "\n"; text_history.push_back( entering_text ); color_history.push_back( enter_color ); color_intensive_history.push_back( enter_intensive ); std::cout << "\ntest\n"; for( int unsigned i = 0; i <= text_history.size(); i++ ) { time_writing( text_history[ i ], color_history[ i ], 0, color_intensive_history[ i ], true, false ); } std::cout << "gdfg"; }
Plik konsola.hpp #ifndef KONSOLA_HPP_INCLUDED #define KONSOLA_HPP_INCLUDED #include <iostream> #include <vector>
class consol { public: int command_list( std::string input ); void enter_text( std::string ae_text, char ae_color, bool ae_intensive, char enter_color, bool enter_intensive ); void time_writing( std::string text, char color, int delay, bool color_intensive, bool skip_space, bool add_history ); };
#endif
plik main.cpp #include <iostream> #include <fstream> #include "konsola.hpp" #include <windows.h> #include <stdlib.h> #include <vector>
int main() { consol konsola; Sleep( 1000 ); konsola.time_writing( "Loading BIOS\n", 'w', 0, true, true, true ); konsola.time_writing( "Welcome to \"Doors\"\n", 'w', 0, false, true, true ); konsola.enter_text( "\n\n>>", 'g', true, 'r', true ); konsola.time_writing( "koniec testu\n", 'w', 0, true, true, true ); return 0; }
|