Calculate MD5 of a string in C++
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 <<<Hello0000000 H e l l o nl0000006
To avoid this, use printf
:
$ printf '%s' Hello | od -ta0000000 H e l l o0000005$ printf '%s' Hello | md5sum8b1a9953c4611296a827abf8c47804d7 -
Alternatively, you could include a newline in your program version:
std::string str("Hello\n");