如何将double转换为BSTR [英] How to convert double to BSTR
本文介绍了如何将double转换为BSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想要为BSTR字符串分配一个双精度值.
此
Want to assign a double value to BSTR string.
Are there any macros /functions for this
推荐答案
是否有任何宏/函数,您可以代表一个带有BSTR
的双精度值,例如
You may just represent a double value with aBSTR
, for instance
#include <windows.h>
#include <tchar.h>
#include <sstream>
using namespace std;
int main()
{
wostringstream wos;
double d = 0.57;
wos << d;
BSTR bstr = SysAllocString(wos.str().c_str());
// enjoy with bstr
// ...
SysFreeString(bstr);
}
#include "windows.h"
#include "comutil.h"
void your_func(BSTR bstr);
int main()
{
_bstr_t str(_variant_t(double(123.456)));
// str is castable to BSTR
// use it like this
your_func(str);
// or simply
your_func(_bstr_t(_variant_t(double(123.456))));
return 0;
}
为什么不使用 VarBstrFromR8 [ ^ ] Windows API?
还有许多其他数据类型转换函数 [
Why not use VarBstrFromR8[^] Windows API?
There are many other Data Type Conversion Functions[^] provided with Windows too.
Best regards
Espen Harlinn
这篇关于如何将double转换为BSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文