Is writing to &str[0] buffer (of a std:string) well-defined behaviour in C++11?

Yes, the code is legal in C++11 because the storage for std::string is guaranteed to be contiguous and your code avoids overwriting the terminating NULL character (or value initialized CharT). From N3337, ยง21.4.5 [string.access] const_reference operator[](size_type pos) const; reference operator[](size_type pos); 1 Requires: pos <= size(). 2 Returns: *(begin() + pos) if pos < size(). … Read more

Vim close buffer but not split window

Like @RusAlex I don’t like plug-ins. I also like to know what code I enter actually does. nmap ,d :b#<bar>bd#<CR> In short this adds a key mapping to vim’s normal mode waiting for key sequence ,d. When executed this switches to a previously open buffer and attempts to delete the buffer you switched away from. … Read more

Possible to calculate MD5 (or other) hash with buffered reads?

You use the TransformBlock and TransformFinalBlock methods to process the data in chunks. // Init MD5 md5 = MD5.Create(); int offset = 0; // For each block: offset += md5.TransformBlock(block, 0, block.Length, block, 0); // For last block: md5.TransformFinalBlock(block, 0, block.Length); // Get the has code byte[] hash = md5.Hash; Note: It works (at least … Read more

endl and flushing the buffer

Output is generally buffered before it’s written to the intended device. That way, when writing to slow to access devices(like files), it doesn’t have to access the device after every single character. Flushing means emptying the buffer and actually writing it to the device.

Char array to hex string C++

Supposing data is a char*. Working example using std::hex: for(int i=0; i<data_length; ++i) std::cout << std::hex << (int)data[i]; Or if you want to keep it all in a string: std::stringstream ss; for(int i=0; i<data_length; ++i) ss << std::hex << (int)data[i]; std::string mystr = ss.str();

What is the use of -fno-stack-protector?

In the standard/stock GCC, stack protector is off by default. However, some Linux distributions have patched GCC to turn it on by default. In my opinion, this is rather harmful, as it breaks the ability to compile anything that’s not linked against the standard userspace libraries unless the Makefile specifically disables stack protector. It would … Read more

What is a buffer in Node.js?

A Buffer is a chunk of memory, just like you would have it in C/C++. You can interpret this memory as an array of integer or floating point numbers of various lengths, or as a binary string. Unlike higher-level data structures like arrays, a buffer is not resizable. It corresponds roughly to: char* or char[] … Read more

std::cout won’t print

Make sure you flush the stream. This is required because the output streams are buffered and you have no guarantee over when the buffer will be flushed unless you manually flush it yourself. std::cout << “Hello” << std::endl; std::endl will output a newline and flush the stream. Alternatively, std::flush will just do the flush. Flushing … Read more