如何将CryptoPP :: Integer转换为char * [英] How to convert CryptoPP::Integer to char*
问题描述
我想将myVar从 CryptoPP:Integer
转换为 char *
或String:代码如下:
I want to convert myVar from CryptoPP:Integer
to char*
or to String :
The code is below :
CryptoPP::Integer myVar = pubKey.ApplyFunction(m);
std::cout << "result: " << std::hex << myVar<< std::endl;
我一直在互联网上寻找将 CryptoPP:Integer
转换为 char *
的方法,但是我没有运气.因此,将 CryptoPP:Integer
转换为 char *
真的是所有人的问题,或者我不太了解类型 CryptoPP:Integer 代码>在C ++中.
I have been searching the Internet for converting CryptoPP:Integer
to char*
but I have had no luck finding. So, either it is really a problem with all to convert CryptoPP:Integer
to char*
, either I didn't understand very well type CryptoPP:Integer
within C++ .
有人可以帮我吗?
推荐答案
除了明确支持<< 以外,不了解
CryptoPP :: Integer
的另一种方法.您的问题所隐含的code>是使用 std :: stringstream
:
One way, without knowing much more about CryptoPP::Integer
other than it clearly supports <<
as implied by your question, is to use std::stringstream
:
std::stringstream ss;
ss << std::hex /*if required*/ << myVar;
使用例如 std :: string s = ss.str();
的方法提取基础的 std :: string
.然后,只要 s
在范围内,就可以使用 s.c_str()
来访问 const char *
缓冲区.调用并依赖 c_str()
的结果后,请勿以任何方式更改 s
,因为这样做并随后依赖该结果的行为是未定义.
Extract the underlying std::string
using, say std::string s = ss.str();
. You can then use s.c_str()
to access the const char*
buffer for as long as s
is in scope. Don't change s
in any way once you've called and relied upon the result of c_str()
as the behaviour of doing so and subsequently relying on that result is undefined.
有一些更整洁的C ++ 11解决方案,但这需要您(和我)对类型有更多了解.
There are neater C++11 solutions but that requires you (and me) to know more about the type.
这篇关于如何将CryptoPP :: Integer转换为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!