简单的问题:double型和int型怎么转换成CString型?

savageka 2003-05-29 08:25:11
用哪个函数啊?
...全文
73 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
XingXing2004 2003-05-29
  • 打赏
  • 举报
回复
Thank You!
dailinviery 2003-05-29
  • 打赏
  • 举报
回复
CString temp;
temp.format("%d",intA);

CString temp;
temp.format("%lf",doubleA);

shzliuhonglin 2003-05-29
  • 打赏
  • 举报
回复
CString temp;
temp.format("%d %lf",yourint,yourdouble);
zxyin1 2003-05-29
  • 打赏
  • 举报
回复
_itoa

/* ITOA.C: This program converts integers of various
* sizes to strings in various radixes.
*/

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;

_itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s\n", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer );

_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer );

_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}

Output
String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2

winplum 2003-05-29
  • 打赏
  • 举报
回复
int i;
double j;
CString msg;
msg.Format("%d",i);
msg.Format("%lf",j);


不要打击年轻人的热情么!
xueyanchao 2003-05-29
  • 打赏
  • 举报
回复
摘自MSDN 2002

Example
/* SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
*/

#include <stdio.h>

void main( void )
{
char buffer[200], s[] = "computer", c = 'l';
int i = 35, j;
float fp = 1.7320534f;

/* Format and print various data: */
j = sprintf( buffer, "\tString: %s\n", s );
j += sprintf( buffer + j, "\tCharacter: %c\n", c );
j += sprintf( buffer + j, "\tInteger: %d\n", i );
j += sprintf( buffer + j, "\tReal: %f\n", fp );

printf( "Output:\n%s\ncharacter count = %d\n", buffer, j );
}

Output
Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71

FAICHEN 2003-05-29
  • 打赏
  • 举报
回复
CString temp;
temp.format("%d %lf",yourint,yourdouble);
你最好以后先查查以前的贴子!这末问的人太多啦!
字符转的各种转换函数库,用这个库,字符串的各种转换再也不头疼 //-------------字符串转数字-------------- int CString_numberStr_2_int(CString str); int stdString_2_int(std::string str);//std string 字符串转int int std_hexString_2_int(std::string str);//std string 字符串转int double CString_2_double(CString in); double stdString_2_double(std::string str);//std string 字符串转double unsigned int hexString_2_u32(std::string str); //-------------数字转字符串-------------- CString CString_int_2_numberStr(int n); CString CString_int_2_numberStr6(int n); std::string stdString_int_2_numberStr(int a); CString double_2_number_CString(double n); std::string double_2_number_String(double a); CString GetCurrWorkingDir(); //获得当前工作路径,不含最后一个字符“\” CString ascii_2_cstring(int ascii);// 把ascii字符转换成对应的字符,返回cstring //-------------字符串转字符串-------------- std::string CString_2_stdString(CString str); CString stdString_2_CString(std::string str); void CString_2_charP(CString str,char *q); //cstring change to ansi string //-------------判断字符串类-------------- bool is_a_double_type_string(CString str); //-------------字符串复杂操作-------------- int break_string(std::string instr, std::string subStr, vectorstring>* subs); //以subStr为标记切割instr为多个单词,存储于subs std::string super_CString::getTimeString(bool fgf);//获得表示当前时间的字符串,fgf表示是否需要分隔符 std::string super_CString::getDateTimeString(bool fgf);//获得表示当前时间和日期的字符串,fgf表示是否需要分隔符 std::string getDateString(bool fgf); //获得表示当前日期的字符串,fgf表示是否需要分隔符 std::string string_trim_LR_space(std::string str);//去除字符串前后的空白字符 std::string string_trim_L_space(std::string str);//去除字符串左边的空白字符 std::string string_trim_R_space(std::string str);//去除字符串右边的空白字符 //-------------GUI相关-------------- CString get_CEdit_text(CEdit* edit); //-------------文件、路径相关-------------- CString calc_CurrWorkingDir_filename(CString str);//返回程序运行的当前路径+filename CString calc_work_full_filename(CString filename,CString path);//path为路径,如果path为空返回程序运行的当前路径+filename,否则返回path+filename。 std::string GetCurrWorkingDir_stdString(); std::string calc_CurrWorkingDir_filename(std::string str); std::string calc_work_full_filename(std::string filename,std::string path);

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧