I have a nice example of memory mapped files that calculates the MD5 hash of a file. That works fine with no problems.
I would like to change it to calculate the MD5 has
You are passing a final newline to the md5sum
program, but not to your code.
You can see that the bash <<<
operator adds a newline:
$ od -ta <<<Hello
0000000 H e l l o nl
0000006
To avoid this, use printf
:
$ printf '%s' Hello | od -ta
0000000 H e l l o
0000005
$ printf '%s' Hello | md5sum
8b1a9953c4611296a827abf8c47804d7 -
Alternatively, you could include a newline in your program version:
std::string str("Hello\n");