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
Ïà¹ØÎĵµ£º
·¢ÌùÇ°ÇëÏȶÁ£ºc/c++ °æ“¾µä”ÎÊÌâ½â´ð
C/C++Ò»Ö±¶¼ÊǵØÇòÉÏʹÓÃ×î¹ã·ºµÄ±à³ÌÓïÑÔ£¬¶øÎÒÃǵÄC/C++°æ×ÔÈ»ÈËÆøÒ²²»²î£¬µ«ÊÇÒ»Ö±¶¼ÓÐһЩºÝ³õ¼¶µÄÎÊÌâÌáÁËÓÖÌᣬ²¢²»ÊÇ˵ÕâЩÎÊÌâÈçºÎÈçºÎµÄ²»ºÃ£¬»¹ÊÇÈçºÎÈçºÎµÄÈõÖÇ£¬ÕâЩÎÊÌâÒ»Ö±¶¼ÊÇÐÂÊÖѧϰµÄ»ù´¡£¬ÊDZØÐëÒª¾¹ýµÄÃż÷£¬ËùÒÔÒ²ÓдæÔڵıØÒª£¬µ«ÊÇÌáµÄ¶àÁË£¬ ......
ÔÙÉÏһƪ£¬ÎÒÃǽéÉÜÁË»ù±¾µ÷ÊÔ¡£Ö®Ç°Ò²ËµÁË£¬Ö®ËùÒ԰ѵ÷ÊÔ·ÅÔÚÇ°Ãæ½²ÊÇÒòΪºóÃæµÄÎÄÕ»ù±¾¶¼»áÓõ½µ÷ÊÔ¡£¹Û²ìÎÒÃǵijÌÐòµ½µ×·¢ÉúÁËʲô¡£ÈÃÎÒÃÇÄܹ»Ö±½ÓÃ÷Á˵Ŀ´Çå³þÎÊÌâµÄ±¾ÖÊ¡£±¾Æª½«ÉîÈëÒ»µã½éÉÜÖ¸ÕëÕâ¸öÈÃÎÞÊý³õѧÕßη¾åµÄ¶«Î÷¡£Ï£Íû´ó¼ÒÔÙ¿´Í걾ƪ֮ºóÄܶÔÖ¸ÕëÓÐеÄÈÏʶ£¬Ö®ºó²»ÔÙ¾åÅÂËü¡£¾õµÃËü¾ÍÄÇô»ØÊ¡£ÄÇÏÂÃæÎÒ ......
CSocketÅÉÉúÓÚCAsyncSocket, ËùÓÐÊ©ÖîÓÚÉϵIJÙ×÷½ÔΪͬ²½²Ù×÷¡£±ÈÈçConnnect,ReceiveµÈ¡£
ͬ²½²Ù×÷µÄÓŵãÊǼòµ¥Ò×Ó㬵«È±µãÒ²ÏÔ¶øÒ×¼û£¬Ð§ÂʵÍÏ£¬ÒòΪÄã±ØÐëµÈµ½Ò»¸ö²Ù×÷Íê³ÉÖ®ºó²ÅÄܽøÐÐÏÂÒ»¸ö²Ù×÷¡£
Èç¹ûÄãºÜ¹ØÐÄЧÂÊ£¬¾ÍÓ¦¸ÃÓÅÏÈʹÓÃCAsyncSocket¡£·´Ö®¾ÍÓÃCSocket¡£
ÏÂÃ潫˵Ã÷ÈçºÎÓÃCSocket´´½¨¼òµ¥µÄ·þÎñÆ÷ºÍ¿Í» ......
1. structµÄ¾Þ´ó×÷ÓÃ
¡¡¡¡Ãæ¶ÔÒ»¸öÈ˵ĴóÐÍC/C++³ÌÐòʱ£¬Ö»¿´Æä¶ÔstructµÄʹÓÃÇé¿öÎÒÃǾͿÉÒÔ¶ÔÆä±àдÕßµÄ
±à³Ì¾Ñé½øÐÐÆÀ¹À¡£ÒòΪһ¸ö´óÐ͵ÄC/C++³ÌÐò£¬ÊƱØÒªÉ漰һЩ(ÉõÖÁ´óÁ¿)½øÐÐÊý¾Ý×éºÏ
µÄ½á¹¹Ì壬ÕâЩ½á¹¹Ìå¿ÉÒÔ½«Ô±¾ÒâÒåÊôÓÚÒ»¸öÕûÌåµÄÊý¾Ý×éºÏÔÚÒ»Æð¡£´ÓijÖ̶ֳÈÉÏÀ´
˵£¬»á²»»áÓÃstruct£¬ÔõÑùÓÃstructÊÇÇø± ......