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

C++ Zapis / Odczytem vektor<unsigned> do pliku binarnego

Ostatnio zmodyfikowano 2014-08-03 23:37
Autor Wiadomość
Haker123
Temat założony przez niniejszego użytkownika
» 2014-08-02 23:27:11
Juz nie wiem co jest nietak

Odczytuje string i unsigned tak
C/C++
Top10_Nick[ i ].resize( Max ); //bez tego tez nie dziala
File.read( reinterpret_cast < char *>( & Top10_Nick[ i ] ), Top10_Nick[ i ].size() );
//oczywiscie w innym miejscu odczytuje unsigned
File.read( reinterpret_cast < char *>( & Top10_Points[ i ] ), sizeof( unsigned ) );

A zapisuje je tak
C/C++
//Top10_Nick[i].resize( Max ) ; z tym tez nie dziala
File.write( Top10_Nick[ i ].c_str(), Top10_Nick[ i ].size() + 1 );
File.write( reinterpret_cast < const char *>( & Top10_Points[ i ] ), sizeof( unsigned ) );

Takie dane mam w zmiennych po odczycie (wypis z konsoli bo string wcale sie nie pokazuje)

Maps->Top10_Points[0] 707406378
Maps->Top10_Nick[0]  ☺   ☺   ☺ ****
Maps->Top10_Points[1] 707406336
Maps->Top10_Nick[1]   ☺   ☺   ☺****
Maps->Top10_Points[2] 707406378
Maps->Top10_Nick[2]    ☺   ☺   ****
Maps->Top10_Points[3] 707406378
Maps->Top10_Nick[3] ☺   ☺   ☺  ****
Maps->Top10_Points[4] 707406378
Maps->Top10_Nick[4]  ☺   ☺   ☺ ****
Maps->Top10_Points[5] 707406336
Maps->Top10_Nick[5]   ☺   ☺   ☺****
Maps->Top10_Points[6] 707406378
Maps->Top10_Nick[6]    ☺   ☺   ****
Maps->Top10_Points[7] 707406378
Maps->Top10_Nick[7] ☺   ☺   ☺  ****
Maps->Top10_Points[8] 707406378
Maps->Top10_Nick[8]  ☺   ☺   ☺ ****
Maps->Top10_Points[9] 707406336
Maps->Top10_Nick[9]   ☺   ☺   ☺****

Wszystkie punkty powinny miec wartosc 0 a string miec 15x * .
Dalej robie cos zle przy zapisie i odczycie??
Przepraszam ze tak mecze ale zawsze mialem problem z plikami binarnymi a na textowych to daleko nie zajade ;/
P-114963
pekfos
» 2014-08-03 00:46:12
Odczytuj tyle, ile zapisujesz. Raz dodajesz 1 do size(), a raz nie. Zdecyduj się też, czy zapisujesz blok Max znaków, czy c-string o maksymalnie Max niezerowych znaków.
P-114964
Haker123
Temat założony przez niniejszego użytkownika
» 2014-08-03 13:42:32
Obojetne czy mam zarezerwowane miejsce stringa na wielkosc Max ( Top10_Nick.resize( Max )) czy nie oraz jak odczytuje z wielkosc +1 lub bez to caly czas mam taki sam efekt. Zaczynam myslec ze to nie tu jest blad bo co nie wpisze to i tak jest zle.

Obecnie tak wyglada kod
Zapis
C/C++
bool Map::Save_Map( ALLEGRO_DISPLAY * display )
{
    ///OTWIERAMY PLIK DO ZAPISU BINARNEGO
    std::ofstream File( File_Name.c_str(), std::ios::out | std::ios::binary );
    //std::cout << "11111" << std::endl ;
    if( !File )
    {
        //std::cout << "22222" << std::endl ;
        al_show_native_message_box( display, "MAP ERROR", "ERROR", "You can not save the map", NULL, ALLEGRO_MESSAGEBOX_ERROR );
        return false;
    }
   
    //std::cout << "33333" << std::endl ;
    int What[ 400 ];
   
    for( int y = 0; y < 400; y++ )
    {
        //Screen_Map[ y * 20 + x ]
        //std::cout << "44444" << std::endl ;
        //for(int x = 0 ; x < 20 ; x++)
        //{
        //PUSTE MIEJSCE 1
        if( Screen_Map[ y ] == Elements[ 15 ] )
        {
            //std::cout << "44411" << std::endl ;
            What[ y ] = 1;
            //File.write( reinterpret_cast<const char*>(&What) , sizeof(char) ) ;
        }
        //SCIANA 2
        else if( Screen_Map[ y ] == Elements[ 16 ] )
        {
            //std::cout << "44422" << std::endl ;
            What[ y ] = 2;
            //File.write( (char*) &What , sizeof(int) ) ;
        }
        //GLOWA WEZA  -[] 3
        else if(( Screen_Map[ y ] == Elements[ 0 ] ) ||( Screen_Map[ y ] == Elements[ 1 ] ) ||
        ( Screen_Map[ y ] == Elements[ 2 ] ) ||( Screen_Map[ y ] == Elements[ 3 ] ) )
        {
            //std::cout << "44433" << std::endl ;
            What[ y ] = 3;
            //File.write( (char*) &What , sizeof(int) ) ;
        }
        //OGON WEZA []-  4
        else if(( Screen_Map[ y ] == Elements[ 8 ] ) ||( Screen_Map[ y ] == Elements[ 9 ] ) ||
        ( Screen_Map[ y ] == Elements[ 10 ] ) ||( Screen_Map[ y ] == Elements[ 11 ] ) )
        {
            //std::cout << "44441" << std::endl ;
            What[ y ] = 4;
            //File.write( (char*) &What , sizeof(int) ) ;
        }
        //}
    }
   
    /////////////////////////////////////////////////////
    File.write( reinterpret_cast < const char *>( & What ), sizeof( What ) );
    //std::cout << "55555" << std::endl ;
    ///WSTAWIAMY KOD
    File.write( Code_Nick.c_str(), Code_Nick.size() + 1 );
   
    //std::cout << "66666" << std::endl ;
    for( int i = 0; i < 10; i++ )
    {
        Top10_Nick[ i ].resize( Max );
        File.write( Top10_Nick[ i ].c_str(), Top10_Nick[ i ].size() + 1 );
        //std::cout << "Top10_Nick[" << i << "].capacity() " << Top10_Nick[i].capacity() << std::endl ;
    }
    al_rest( 5 );
    //(const char*)
   
    //std::cout << "77777" << std::endl ;
    ///KOLEJNY KOD
    File.write( Code_Point.c_str(), Code_Point.size() + 1 );
   
    for( int i = 0; i < 10; i++ )
         File.write( reinterpret_cast < const char *>( & Top10_Points[ i ] ), sizeof( unsigned ) );
    //std::cout << "88888" << std::endl ;
   
    File.write( Check_File.c_str(), Check_File.size() + 1 );
   
    //std::cout << "99999" << std::endl ;
    File.close();
   
    return true;
}

Odczyt
C/C++
bool Map::Load_Map( ALLEGRO_DISPLAY * display, std::string Name )
{
    File_Name = "Maps\\" + Name;
    //OTWIERAMY PLIK DO ODCZYTU BINARNEGO
    std::fstream File;
    File.open( File_Name.c_str(), std::ios::in | std::ios::binary );
   
    if( !File )
    {
        al_show_native_message_box( display, "MAP ERROR", "ERROR", "You can not open the map, possible that the map does not exist", NULL, ALLEGRO_MESSAGEBOX_ERROR );
        return false;
    }
   
    //CO MAMY WGRAC DO MAPY
    int What[ 400 ];
   
    File.read( reinterpret_cast < char *>( & What ), sizeof( What ) );
   
    for( int y = 0; y < 400; y++ )
    {
        //PUSTE MIEJSCE
        if( What[ y ] == 1 )
             Screen_Map[ y ] = Elements[ 15 ];
        //SCIANA
        else if( What[ y ] == 2 )
             Screen_Map[ y ] = Elements[ 16 ];
        //GLOWA WEZA  -[]
        else if( What[ y ] == 3 )
        {
            std::cout << "Y W ODCZYCIE MAPY = " << y << std::endl;
           
            //POBIERAMY POZYCJE WEZA
            Snakess->Snake[ 0 ][ 0 ] = y % 20;
            Snakess->Snake[ 0 ][ 1 ] = y / 20;
           
            Screen_Map[ y ] = Elements[ 0 ];
        }
        //OGON WEZA []-
        else if( What[ y ] == 4 )
        {
           
            //POBIERAMY POZYCJE WEZA
            Snakess->Snake[ 1 ][ 0 ] = y % 20;
            Snakess->Snake[ 1 ][ 1 ] = y / 20;
           
            Screen_Map[ y ] = Elements[ 8 ];
        }
    }
   
    ///POBIERAMY MIEJSCE NICKOW W PLIKU
    int place = Return_Place_of_String( File, Code_Nick );
   
    if( place == - 1 )
    {
        al_show_native_message_box( display, "ERROR", "ERROR FILE", "FILE DONT HAVE TOP10 NICK", NULL, ALLEGRO_MESSAGEBOX_ERROR );
        return false;
    }
    ///USTAWIAMY WSKAZNIK DO CZYTANIA (seekp WSKAZNIK PISANIA)
    File.seekg( place );
    for( int i = 0; i < 10; i++ )
    {
        Top10_Nick[ i ].resize( Max );
        File.read( reinterpret_cast < char *>( & Top10_Nick[ i ] ), Top10_Nick[ i ].size() + 1 );
        //std::cout << "Top10_Nick[" << i << "].capacity() " << Top10_Nick[i].capacity() << std::endl ;
       
        //= a ;
    }
    al_rest( 5 );
    ///POBIERAMY MIEJSCE PUNKTY W PLIKU
    place = Return_Place_of_String( File, Code_Point );
   
    if( place == - 1 )
    {
        al_show_native_message_box( display, "ERROR", "ERROR FILE", "FILE DONT HAVE TOP10 POINTS", NULL, ALLEGRO_MESSAGEBOX_ERROR );
        return false;
    }
   
    File.seekg( place );
    for( int i = 0; i < 10; i++ )
         File.read( reinterpret_cast < char *>( & Top10_Points[ i ] ), sizeof( unsigned ) );
   
    File.close();
   
    ///POPRAWIAMY ZDJECIA WEZA (ZEBY PASOWALY DO SWOICH POZYCJI)
    for( int y = 0; y < 20; y++ )
    {
        for( int x = 0; x < 20; x++ )
        {
            if( Screen_Map[( y * 20 ) + x ] == Elements[ 0 ] )
            {
                if( x == 0 && y == 0 )
                {
                    std::cout << " x == 0 && y == 0 " << std::endl;
                    if( Screen_Map[( y + 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y + 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 1 ];
                        Screen_Map[( y + 1 ) * 20 + x ] = Elements[ 9 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = UP;
                    }
                    else if( Screen_Map[ y * 20 + x + 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x + 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 0 ];
                        Screen_Map[ y * 20 + x + 1 ] = Elements[ 8 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = LEFT;
                    }
                } //if( x == 0 && y == 0 )
                else if( x == 19 && y == 19 )
                {
                    std::cout << " x == 19 && y == 19 " << std::endl;
                    if( Screen_Map[( y - 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y - 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 3 ];
                        Screen_Map[( y - 1 ) * 20 + x ] = Elements[ 11 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = DOWN;
                    }
                    else if( Screen_Map[ y * 20 + x - 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x - 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 2 ];
                        Screen_Map[ y * 20 + x - 1 ] = Elements[ 10 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                } //else if( x == 19 && y == 19 )
                else if( x == 19 && y == 0 )
                {
                    std::cout << " x == 19 && y == 0 " << std::endl;
                    if( Screen_Map[( y + 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y + 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 1 ];
                        Screen_Map[( y + 1 ) * 20 + x ] = Elements[ 9 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = UP;
                    }
                    else if( Screen_Map[ y * 20 + x - 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x - 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 2 ];
                        Screen_Map[ y * 20 + x - 1 ] = Elements[ 10 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                } //else if( x == 19 && y == 0 )
                else if( x == 0 && y == 19 )
                {
                    std::cout << " x == 0 && y == 19 " << std::endl;
                    if( Screen_Map[( y - 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y - 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 3 ];
                        Screen_Map[( y - 1 ) * 20 + x ] = Elements[ 11 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = DOWN;
                    }
                    else if( Screen_Map[ y * 20 + x + 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x + 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 0 ];
                        Screen_Map[ y * 20 + x + 1 ] = Elements[ 8 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = LEFT;
                    }
                } //else if( x == 0 && y == 19 )
                else if( y == 0 )
                {
                    std::cout << " y == 0 " << std::endl;
                    if( Screen_Map[( y + 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y + 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 1 ];
                        Screen_Map[( y + 1 ) * 20 + x ] = Elements[ 9 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = UP;
                    }
                    else if( Screen_Map[ y * 20 + x - 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x - 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 2 ];
                        Screen_Map[ y * 20 + x - 1 ] = Elements[ 10 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                    else if( Screen_Map[ y * 20 + x + 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x + 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 0 ];
                        Screen_Map[ y * 20 + x + 1 ] = Elements[ 8 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = LEFT;
                    }
                } //else if( y == 0 )
                else if( y == 19 )
                {
                    std::cout << " y == 19 " << std::endl;
                    if( Screen_Map[( y - 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y - 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 3 ];
                        Screen_Map[( y - 1 ) * 20 + x ] = Elements[ 11 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = DOWN;
                    }
                    else if( Screen_Map[ y * 20 + x - 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x - 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 2 ];
                        Screen_Map[ y * 20 + x - 1 ] = Elements[ 10 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                    else if( Screen_Map[ y * 20 + x + 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x + 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 0 ];
                        Screen_Map[ y * 20 + x + 1 ] = Elements[ 8 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = LEFT;
                    }
                } //else if( y == 19 )
                else if( x == 0 )
                {
                    std::cout << " X == 0 " << std::endl;
                    if( Screen_Map[( y + 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y + 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 1 ];
                        Screen_Map[( y + 1 ) * 20 + x ] = Elements[ 9 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = UP;
                    }
                    else if( Screen_Map[( y - 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y - 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 3 ];
                        Screen_Map[( y - 1 ) * 20 + x ] = Elements[ 11 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                    else if( Screen_Map[ y * 20 + x + 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x + 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 0 ];
                        Screen_Map[ y * 20 + x + 1 ] = Elements[ 8 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = LEFT;
                    }
                } //else if( x == 0 )
                else if( x == 19 )
                {
                    std::cout << " X == 19 " << std::endl;
                    if( Screen_Map[( y + 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y + 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 1 ];
                        Screen_Map[( y + 1 ) * 20 + x ] = Elements[ 9 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = UP;
                    }
                    else if( Screen_Map[( y - 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y - 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 3 ];
                        Screen_Map[( y - 1 ) * 20 + x ] = Elements[ 11 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = DOWN;
                    }
                    else if( Screen_Map[ y * 20 + x - 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x - 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 2 ];
                        Screen_Map[ y * 20 + x - 1 ] = Elements[ 10 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                } //else if( x == 19 )
                else
                {
                    std::cout << "ELSE" << std::endl;
                    if( Screen_Map[( y + 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y + 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 1 ];
                        Screen_Map[( y + 1 ) * 20 + x ] = Elements[ 9 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = UP;
                    }
                    else if( Screen_Map[( y - 1 ) * 20 + x ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ (y - 1) * 20 + x ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 3 ];
                        Screen_Map[( y - 1 ) * 20 + x ] = Elements[ 11 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = DOWN;
                    }
                    else if( Screen_Map[ y * 20 + x - 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x - 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 2 ];
                        Screen_Map[ y * 20 + x - 1 ] = Elements[ 10 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = RIGHT;
                    }
                    else if( Screen_Map[ y * 20 + x + 1 ] == Elements[ 8 ] )
                    {
                        std::cout << "                    W Screen_Map[ y * 20 + x + 1 ] == Elements[8]" << std::endl;
                        Screen_Map[ y * 20 + x ] = Elements[ 0 ];
                        Screen_Map[ y * 20 + x + 1 ] = Elements[ 8 ];
                       
                        //USTALAMY KIERUNEK WEZA
                        dir = LEFT;
                    }
                } //else
            } //if(Screen_Map[ (y * 20) + x ] == Elements[0])
        } //for(int x = 0 ; x < 20 ; x++)
    } //for(int y = 0 ; y < 20 ; y++)
   
    std::cout << " ZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAA " << std::endl;
   
    return true;
}
P-114978
pekfos
» 2014-08-03 13:46:51
C/C++
File.read( reinterpret_cast < char *>( & Top10_Nick[ i ] ), Top10_Nick[ i ].size() + 1 );
Nie możesz tak zapisać/odczytać. Znowu.
P-114979
Haker123
Temat założony przez niniejszego użytkownika
» 2014-08-03 13:53:55
Skasowalem to +1 z odczytu i dalej nie dziala.
P-114981
pekfos
» 2014-08-03 13:57:25
Nie możesz tak zapisać/odczytać obiektu typu std::string.. Użyj std::getline() z odpowiednimi argumentami, lub odczytuj przez read() do tablicy znaków i potem skopiuj ją do obiektu std::string - zależy od tego, co konkretnie chcesz osiągnąć.
P-114983
Haker123
Temat założony przez niniejszego użytkownika
» 2014-08-03 14:31:43
Sprawdzilem z ciekawosci co funkcja int Return_Place_of_String( std::fstream &File , std::string Searches ) zwraca, i okazuje sie ze czy szukaniu Code_Nick zwraca 11 a przy Code_Point zwraca 1622 i w te miejsca ustawiam odczyt danych. Na poczatku mam 400 elementow int potem Code_Nick i niki graczy, to jest o wiele wiecej niz 11.

Co ja tutaj robie zle??
Funkcja odszukuje string w pliku i pobiera jego pozycje.

C/C++
int Return_Place_of_String( std::fstream & File, std::string Searches )
{
   
    std::string a(( std::istreambuf_iterator < char >( File ) ), std::istreambuf_iterator < char >() );
   
    //std::istreambuf_iterator<int>()
    //SZUKAMY W PLIKU STRINGA
    int i = a.find( Searches );
    //std::search( File.beg , File.end , Searches.begin() , Searches.end() ) ;
   
    if( i == - 1 )
         return - 1;
    else
         return i + Searches.length() + 1;
   
}
P-114988
Monika90
» 2014-08-03 14:53:46
A wiesz, są biblioteki do serializacji i deserializacji danych, np. cereal
http://uscilab.github.io​/cereal/
nie ma ona problemu z zapisaniem wektora stringów, std::map, itp.., czy to w trybie binarnym, xml czy jason.
P-114990
1 2 3 « 4 » 5
Poprzednia strona Strona 4 z 5 Następna strona