Calculate MD5 of a string in C++

自闭症网瘾萝莉.ら 提交于 2019-12-04 22:55:33

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!