C read binary stdin

前端 未结 8 2211
难免孤独
难免孤独 2020-11-30 04:51

I\'m trying to build an instruction pipeline simulator and I\'m having a lot of trouble getting started. What I need to do is read binary from stdin, and then store it in me

8条回答
  •  感动是毒
    2020-11-30 05:43

    For Windows, this Microsoft _setmode example specifically shows how to change stdin to binary mode:

    // crt_setmode.c
    // This program uses _setmode to change
    // stdin from text mode to binary mode.
    
    #include 
    #include 
    #include 
    
    int main( void )
    {
       int result;
    
       // Set "stdin" to have binary mode:
       result = _setmode( _fileno( stdin ), _O_BINARY );
       if( result == -1 )
          perror( "Cannot set mode" );
       else
          printf( "'stdin' successfully changed to binary mode\n" );
    }
    

提交回复
热议问题