gpt4 book ai didi

C++ MFC double 到 CString

转载 作者:太空狗 更新时间:2023-10-29 19:43:59 25 4
gpt4 key购买 nike

对不起我的英语。

我需要将 double 值转换为 CString,因为我需要执行 AfxMessageBox(double_value);

我发现了这个:

std::ostringstream ost;
ost << double_value;
std::cout << "As string: " << ost.str() << std::endl;
//AfxMessageBox(ost.str()); - Does not work.

我该怎么做?

最佳答案

AfxMessageBox 需要一个 CString 对象,因此将 double 格式化为 CString 并传递:

CString str;
str.Format("As string: %g", double);
AfxMessageBox(str);

编辑:如果您希望值显示为整数(小数点后没有值),请改用此值:

str.Format("As string: %d", (int)double);

关于C++ MFC double 到 CString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17259213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com