Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

"Zacinanie się programu" [C++]

Ostatnio zmodyfikowano 2018-10-07 17:28
Autor Wiadomość
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
C/C++
#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' ) { //wybieranie koloru
        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 ] != ' ' ) //je¿eli nasptepnym znakiem jest spacja wypisz ja bez opoznienia
             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 );
        /*
                    while(kbhit()==true){
       
                    switch(first_char){
                        case 27: //escape
       
                        break;
                        case 8: //backspace
                            if(entering_text.size()>=1)
                            entering_text.erase(entering_text.size(),entering_text.size());
                        break;
                        case 0: //F1-F10 + (Num_kayboard 9-0+ Num_keybord ,) with Num keyboard off + znaki z altem nie znajdujace sie w jezyku klawiatury
       
                        break;
                        case 224: //insert-PG_down
       
                        break;
                        default:
                            if(first_char>=32&&first_char<=126)
                            entering_text+=first_char;
                        break;
                    }}
        */
        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";
    //system("cls");
    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"; //Oznaczenie o którym mówiłem<------------------------------------------------------------------------------
}

Plik konsola.hpp
C/C++
#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 // KONSOLA_HPP_INCLUDED

plik main.cpp
C/C++
#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;
}

P-172560
pekfos
» 2018-10-07 17:23:14
C/C++
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 );
}
Przekraczasz zakres tablicy.
P-172561
EnderstevePL
Temat założony przez niniejszego użytkownika
Wielkie dzięki. <3
» 2018-10-07 17:28:29
Czasami to ja chyba naprawdę nie myślę.
Dzięki za pomoc. :)
P-172562
« 1 »
  Strona 1 z 1