举例说明CString类的Format(...)的用法。 举例说明CString类的Format(...)的用法。谢谢,放分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString str;str.Format("%d", 1); // str == "1"其余格式控制符参照printf CString str;str.Format("%d", 1); CString str;int a;str.Format("%d", a); CString str = "Some Data";str.Format(_T("%s%d"), str, 123) ); str.Format(_T("Floating point: %.2f\n"), 12345.12345);str.Format(_T("Left-justified integer: %.6d\n"), 35);str.Format(IDS_SCORE, 5, 3); 和printf类似http://www.vcshare.net/c/ CString str;char ch;str.Format("%c", ch); CString errormessage;errormessage.Format("連接數據庫失敗!\r\n錯誤信息:%s",e.ErrorMessage()); int x = 123;CString str;str.Format("%d", x); // 123str.Format("%6d", x); // 123str.Format("%06d", x); //000123str.Format("%x", x); //7bstr.Format("%X", x); //7Bstr.Format("%04x", x); //007bfloat x = 123.456;str.Format("%f", x); // 123.456str.Format("%2.3f"); // 123.456str.Format("%4.2f"); // 123.45 记住, 和printf()中的大体一致 int i = 10; double fp = 1.5; CString str; char c = '\n'; str.Format( "你好%c", c ); //str的值 你好\n str.Format( "%d", i ); str.Format( "%f", fp ); 来晚了,查查msdn就全知道了。 顺路问一句,我所说的跟上面所提到的直接将 int 向转化有些不同。在一个CString 变量中存放的是数字,如果想依据这个数字的长度来确定前面是否加零。比如说数字是 3 则转化为 03 ,如果是16 则原样存为 16.请教该如何实现。 str.Format("%02d", i); //2指示长度,0指不够长时在前加"0"//3 -> "03"//16 -> "16 CString str;str.Format(_T("Floating point: %.2f\n"), 12345.12345);_tprintf(_T("%s"), (LPCTSTR) str);str.Format(_T("Left-justified integer: %.6d\n"), 35);_tprintf(_T("%s"), (LPCTSTR) str);str.Format(IDS_SCORE, 5, 3);_tprintf(_T("%s"), (LPCTSTR) str); CString str;str.Format(_T("Floating point: %.2f\n"), 12345.12345);_tprintf(_T("%s"), (LPCTSTR) str);str.Format(_T("Left-justified integer: %.6d\n"), 35);_tprintf(_T("%s"), (LPCTSTR) str);str.Format(IDS_SCORE, 5, 3);_tprintf(_T("%s"), (LPCTSTR) str); 对内存消耗熟悉的进来,高手速进!!!! WinMain()的句柄怎么得到 WSARecv接收问题 非阻塞 在加 #include "afxmt.h" 头文件的时候出问题了 无模式对话框类中取得View指针的问题,恳请指点 建立索引是干什么啊 送分:DAO数据库中,如何使用动态的数据源?? win7系统文件重命名功能如何实现? 如何改变 最大化 最小化以及关闭按钮的位置。 计算机本科生是否有必要考“高级程序员”? 奇怪的输入问题 如何实现在任务栏中图标的闪烁
str.Format("%d", 1); // str == "1"
其余格式控制符参照printf
str.Format("%d", 1);
int a;
str.Format("%d", a);
str.Format(_T("%s%d"), str, 123) ); str.Format(_T("Floating point: %.2f\n"), 12345.12345);str.Format(_T("Left-justified integer: %.6d\n"), 35);str.Format(IDS_SCORE, 5, 3);
http://www.vcshare.net/c/
char ch;
str.Format("%c", ch);
errormessage.Format("連接數據庫失敗!\r\n錯誤信息:%s",e.ErrorMessage());
CString str;
str.Format("%d", x); // 123
str.Format("%6d", x); // 123
str.Format("%06d", x); //000123
str.Format("%x", x); //7b
str.Format("%X", x); //7B
str.Format("%04x", x); //007bfloat x = 123.456;
str.Format("%f", x); // 123.456
str.Format("%2.3f"); // 123.456
str.Format("%4.2f"); // 123.45
double fp = 1.5;
CString str;
char c = '\n'; str.Format( "你好%c", c ); //str的值 你好\n
str.Format( "%d", i );
str.Format( "%f", fp );
请教该如何实现。
//3 -> "03"
//16 -> "16
_tprintf(_T("%s"), (LPCTSTR) str);str.Format(_T("Left-justified integer: %.6d\n"), 35);
_tprintf(_T("%s"), (LPCTSTR) str);str.Format(IDS_SCORE, 5, 3);
_tprintf(_T("%s"), (LPCTSTR) str);
_tprintf(_T("%s"), (LPCTSTR) str);str.Format(_T("Left-justified integer: %.6d\n"), 35);
_tprintf(_T("%s"), (LPCTSTR) str);str.Format(IDS_SCORE, 5, 3);
_tprintf(_T("%s"), (LPCTSTR) str);