There is a file fbx binaru. tried to read using ifstream but it reads up to a certain character and does not read the file anymore (approximately 10-12 characters)

string line; ifstream myfile("C:/Users/wARTEMw/Desktop/object/Blender_Binary.fbx"); if (myfile.is_open()) { while (myfile.good()) { getline(myfile, line); cout << line; } myfile.close(); } 

  • 2
    Well, who reads a binary file as text ... - Harry

2 answers 2

When opening it is necessary to indicate that the file should be read in binary mode. To do this, use the second parameter of the constructor:

 ifstream myfile( "C:/Users/wARTEMw/Desktop/object/Blender_Binary.fbx", ifstream::in | ifstream::binary ); 
     std::ifstream fs("C:/Users/wARTEMw/Desktop/object/Blender_Binary.fbx", std::ios::in | std::ios::binary ); // Узнаём размер файла fs.seekg( 0, std::ios::end ); std::size_t size = fs.tellg(); fs.seekg( 0, std::ios::beg ); // Читаем файл целиком std::unique_ptr <char[]> buf; buf.reset( new char[size] ); fs.read( buf.get(), size ); /* либо без std::unique_ptr char* buf = new char[size]; fs.read( buf, size ); и нужно не забыть освободить память delete []buf; */ 

    when you need to display all the characters you need to consider that the output will go to the control characters, that is, if you get '\ 0', the output will stop

    so if you need to display the contents on the screen or in a file, you need to label these characters like that (like in Notepad ++)

     // примерно так for( int i = 0; i < size; ++i ){ if( buf[ i ] == '\0' ) printf( "[NUL]" ); else if( buf[ i ] == '\1' ) printf( "[SOH]" ); else if( buf[ i ] == '\2' ) printf( "[STX]" ); else if( buf[ i ] == '\3' ) printf( "[ETX]" ); else if( buf[ i ] == '\4' ) printf( "[EOT]" ); else if( buf[ i ] == '\5' ) printf( "[ENQ]" ); else if( buf[ i ] == '\6' ) printf( "[ACK]" ); else if( buf[ i ] == '\7' ) printf( "[BEL]" ); else if( buf[ i ] == '\n' ) printf( "\n" ); else printf( "%c", buf[i] ); }