Accept user input

GHJUYGHJKLKUJHM;&MJ:6AG9F5D8V)A8%]>75Q;6EE85U955%-245!/3DU,2TI) M2$=&141#0D% /SX]/#LZ.3@W-C4T,S(Q,”\N+2PK*BDH)R8E)”,B(7Y]?’MZ M>7AW=G5T<W)Q<&]N;6QK:FEH9V9E9&-B86!?7EU<6UI96%=655134E%03TY- Untested, but should work.

Checking if a file opened successfully with ifstream

You can simply do this: int devices::open_file(std::string _file_name) { ifstream input_stream; input_stream.open(_file_name.c_str(), ios::in); if(!input_stream) { return -1; } file_name = _file_name; return 0; } fail() is not a static method, you must call it on an instance not a type, so if you want to use fail(), replace !input_stream with input_stream.fail() in my code above. … Read more

Why can Haskell exceptions only be caught inside the IO monad?

One of the reasons is the denotational semantics of Haskell. One of the neat properties of (pure) Haskell functions is their monotonicity — more defined argument yields more defined value. This property is very important e.g. to reason about recursive functions (read the article to understand why). Denotation of exception by definition is the bottom, … Read more

Read from file or stdin

You’re thinking it wrong. What you are trying to do: If stdin exists use it, else check whether the user supplied a filename. What you should be doing instead: If the user supplies a filename, then use the filename. Else use stdin. You cannot know the total length of an incoming stream unless you read … Read more

C++ Streams vs. C-style IO?

This is an heated topic. Some people prefer to use the C++ IO since they are type-safe (you can’t have divergence between the type of the object and the type specified in the format string), and flow more naturally with the rest of the C++ way of coding. However, there is also arguments for C … Read more

Why is reading one byte 20x slower than reading 2, 3, 4, … bytes from a file?

I was able to reproduce the issue with your code. However, I noticed the following: can you verify that the issue disappears if you replace file.seek(randint(0, file.raw._blksize), 1) with file.seek(randint(0, file.raw._blksize), 0) in setup? I think you might just run out of data at some point during reading 1 byte. Reading 2 bytes, 3 bytes … Read more

How to read a struct from a file in Rust?

Here you go: use std::io::Read; use std::mem; use std::slice; #[repr(C, packed)] #[derive(Debug, Copy, Clone)] struct Configuration { item1: u8, item2: u16, item3: i32, item4: [char; 8], } const CONFIG_DATA: &[u8] = &[ 0xfd, // u8 0xb4, 0x50, // u16 0x45, 0xcd, 0x3c, 0x15, // i32 0x71, 0x3c, 0x87, 0xff, // char 0xe8, 0x5d, 0x20, 0xe7, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)