c/c++ Êý×Öת³É×Ö·û´®, ×Ö·û´®×ª³ÉÊý×Ö
Êý×Öת×Ö·û´®£º
ÓÃC++µÄstreanstream:
#include <sstream>
#Include <string>
string num2str(double i)
...{
stringstream ss;
ss<<i;
return ss.str();
}
×Ö·û´®×ªÊý×Ö£º
int str2num(string s)
...{
int num;
stringstream ss(s);
ss>>num;
return num;
}
ÉÏÃæ·½·¨ºÜ¼ò±ã, ȱµãÊÇ´¦Àí´óÁ¿Êý¾Ýת»»ËٶȽÏÂý..
C libraryÖеÄsprintf, sscanf Ïà¶Ô¸ü¿ì
¿ÉÒÔÓÃsprintfº¯Êý½«Êý×ÖÊä³öµ½Ò»¸ö×Ö·û»º³åÇøÖÐ. ´Ó¶ø½øÐÐÁËת»»...
ÀýÈ磺
ÒÑÖª´Ó0µã¿ªÊ¼µÄÃëÊý(seconds) £¬¼ÆËã³ö×Ö·û´®"H:M:S", ÆäÖÐHÊÇСʱ, M£½·ÖÖÓ£¬S£½Ãë
int H, M, S;
string time_str;
H=seconds/3600;
M=(seconds%3600)/60;
S=(seconds%3600)%60;
char ctime[10];
sprintf(ctime, "%d:%d:%d", H, M, S); // ½«ÕûÊýת»»³É×Ö·û´®
time_str=ctime; // ½á¹û
Óësprintf¶ÔÓ¦µÄÊÇsscanfº¯Êý, ¿ÉÒÔ½«×Ö·û´®×ª»»³ÉÊý×Ö
char str[] = "15.455";
int i;
float fp;
ssca
Ïà¹ØÎĵµ£º
ÊÂÇéÓ¦¸Ã±»×öµÃ¾¡¿ÉÄܵļòµ¥£¬µ«²»ÊÇÈÎÒâµØ¼òµ¥»¯¡£
¨D¨D°®Òò˹̹
ËäÈ»×öºÃµÄ³ÌÐòÄÜ°´ÏîÄ¿ÐèÇóÕýÈ·ÔËÐе½×îºóÒ»²½£¬µ«ÔÚǶÈëʽϵͳ¿ª·¢Öв¢²»×ÜÊÇÄܳɹ¦µÄ¡£ÓÉÓڵͳɱ¾µÄÐèÒªÓ²¼þÉè¼ÆÕß¼¸ºõ²»¿ÉÄÜÉè¼Æ³ö×ã¹»µÄÄÚ´æºÍ´¦ÀíÆ÷ÐÔÄÜÀ´Ê¹µÃ³ÌÐòÄܱ»ÔËÐС£µ±È»£¬ÔÚÈí¼þ¿ª·¢¹ý³ÌÖÐʹµÃ³ÌÐòÄܹ»ÕýÈ·ÔËÐÐÊǸüÖØÒªµÄ¡£ÎªÁËÕâµã£¬Í¨³£ ......
1.×Ô¶¨ÒåÊä³ö
Ïë±Ø´ó¼Ò¶¼ÓÐÀûÓÃÊä³öº¯ÊýÈçprintfÀ´°ïÖúÎÒÃǵ÷ÊÔ³ÌÐòµÄ¾Àú£¬ÕâÊÇÒ»ÖֱȽÏÔʼµÄ³ÌÐòµ÷ÊÔ¸¨Öú·½·¨£¬ÔÚLinuxÏÂÒ²¿ÉÒÔΪÎÒÃÇËùÓᣲ»¹ýÕâÖÖ·½·¨ÓÐÒ»¸öÃ÷ÏÔµÄȱµã£¬¾ÍÊÇÔÚµ÷ÊÔÍêºóÎÒÃDZØÐë×¢ÊÍ»òɾ³ýµôÕâЩ¸¨Öú´úÂë¡£Linux CÌṩÁË-DDEBUGÕâ¸ö±àÒë±ê¼ÇÀ´¶¨ÒåDEBUGÕâ¸ö·ûºÅ£¬½èÖúÓڸ÷ûºÅ£¬ÎÒÃÇ¿ÉÒÔÔÚÓ¦Ó ......
VCÖÐÏÂÃ漸¸ö½á¹¹Ìå´óС·Ö±ðÊǶàÉÙÄØ
struct MyStruct
{
double m4;
char m1;
int m3£»
};
struct MyStruct {
  ......
×î½üά»¤Logger¹²Ïí¿âµÄʱºòÐÂÔöÁ˸üÈËÐÔ»¯µÄ×Ô¶¯´´½¨¸÷¼¶Ä¿Â¼µÄ¹¦ÄÜ£¬ÏÂÃæÊÇÎÒʵÏÖ´´½¨ÖîÈç "c:\a\b\c\d\yeah.log"Öеĸ÷¼¶Îļþ¼ÐµÄ¹ý³Ì£¬Çë´ó¼ÒÖ¸½Ì£¡
BOOL CreateDirectoryInPathW(const wchar_t *sLogPath)
{
static BOOL bRet = 0;
CString csFullDir(_T(""));//Ôʼȫ·¾¶
int nLen = 0;//ÔÊ ......