C++ string Ïê½â
C++ string Ïê½â
2007-04-22 11:05
Ç°ÑÔ: string µÄ½ÇÉ«
1 string ʹÓÃ
1.1 ³ä·ÖʹÓÃstring ²Ù×÷·û
1.2 ÑÛ»¨çÔÂÒµÄstring find º¯Êý
1.3 string insert, replace, erase 2 string ºÍ C·ç¸ñ×Ö·û´®
3 string ºÍ Charactor Traits
4 string ½¨Òé
5 С½á
6 ¸½Â¼Ç°ÑÔ: string µÄ½ÇÉ«
C++ ÓïÑÔÊǸöÊ®·ÖÓÅÐãµÄÓïÑÔ£¬µ«ÓÅÐã²¢²»±íʾÍêÃÀ¡£»¹ÊÇÓÐÐí¶àÈ˲»Ô¸ÒâʹÓÃC»òÕßC++£¬ÎªÊ²Ã´£¿ÔÒòÖڶ࣬ÆäÖÐÖ®Ò»¾ÍÊÇC/C++µÄÎı¾´¦Àí¹¦ÄÜÌ«Âé·³£¬ÓÃÆðÀ´ºÜ²»·½±ã¡£ÒÔǰûÓнӴ¥¹ýÆäËûÓïÑÔʱ£¬Ã¿µ±±ðÈËÕâô˵£¬ÎÒ×ÜÊDz»Ð¼Ò»¹Ë£¬ÈÏΪËûÃǸù±¾¾ÍûÓÐÁì»áC++µÄ¾«»ª£¬»òÕß²»Ì«¶®C++£¬ÏÖÔÚÎÒ½Ó´¥perl, php, ºÍShell½Å±¾ÒԺ󣬿ªÊ¼Àí½âÁËÒÔǰΪʲôÓÐÈË˵C++Îı¾´¦Àí²»·½±ãÁË¡£
¾ÙÀýÀ´Ëµ£¬Èç¹ûÎı¾¸ñʽÊÇ£ºÓû§Ãû µç»°ºÅÂ룬ÎļþÃûname.txt
Tom 23245332
Jenny 22231231
Heny 22183942
Tom 23245332
...
ÏÖÔÚÎÒÃÇÐèÒª¶ÔÓû§ÃûÅÅÐò£¬ÇÒÖ»Êä³ö²»Í¬µÄÐÕÃû¡£
ÄÇôÔÚshell ±à³ÌÖУ¬¿ÉÒÔÕâÑùÓãº
awk '{print $1}' name.txt | sort | uniq
¼òµ¥°É£¿
Èç¹ûʹÓÃC/C++ ¾ÍÂé·³ÁË£¬ËûÐèÒª×öÒÔϹ¤×÷£º
ÏÈ´ò¿ªÎļþ£¬¼ì²âÎļþÊÇ·ñ´ò¿ª£¬Èç¹ûʧ°Ü£¬ÔòÍ˳ö¡£
ÉùÃ÷Ò»¸ö×ã¹»´óµÃ¶þά×Ö·ûÊý×é»òÕßÒ»¸ö×Ö·ûÖ¸ÕëÊý×é
¶ÁÈëÒ»Ðе½×Ö·û¿Õ¼ä
È»ºó·ÖÎöÒ»ÐеĽṹ£¬ÕÒµ½¿Õ¸ñ£¬´æÈë×Ö·ûÊý×éÖС£
¹Ø±ÕÎļþ
дһ¸öÅÅÐòº¯Êý£¬»òÕßʹÓÃдһ¸ö±È½Ïº¯Êý£¬Ê¹ÓÃqsortÅÅÐò
±éÀúÊý×飬±È½ÏÊÇ·ñÓÐÏàͬµÄ£¬Èç¹ûÓУ¬ÔòҪɾ³ý£¬copy...
Êä³öÐÅÏ¢
Äã¿ÉÒÔÓÃC++»òÕßCÓïÑÔȥʵÏÖÕâ¸öÁ÷³Ì¡£Èç¹ûÒ»¸öÈ˵ÄÖ÷Òª¹¤×÷¾ÍÊÇ´¦ÀíÕâÖÖÀàËƵÄÎı¾(ÀýÈç×öapacheµÄÈÕ־ͳ¼ÆºÍ·ÖÎö),Äã˵Ëû»áϲ»¶C/C++ô£¿
µ±È»£¬ÓÐÁËSTL£¬ÕâЩ´¦Àí»áµÃµ½ºÜ´óµÄ¼ò»¯¡£ÎÒÃÇ¿ÉÒÔʹÓà fstreamÀ´´úÌæÂé·³µÄfopen fread fclose, ÓÃvector À´´úÌæÊý×é¡£×îÖØÒªµÄÊÇÓà stringÀ´´úÌæchar * Êý×飬ʹÓÃsortÅÅÐòËã·¨À´ÅÅÐò£¬ÓÃunique º¯ÊýÀ´È¥ÖØ¡£ÌýÆðÀ´ºÃÏñºÜ²»´í ¡£¿´¿´ÏÂÃæ´úÂë(Àý³Ì1£©£º
££i nclude <string>
££i nclude <iostream>
££i nclude <algorithm>
££i nclude <vector>
££i nclude <fstream>
using namespace std;
int main(){
ifstream in("name.txt");
string strtmp;
&n
Ïà¹ØÎĵµ£º
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£ºUTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Time£¨ÈÕÀúʱ¼ä£©£¬epoch£¨Ê±¼ä ......
http://uncrustify.sourceforge.net/
Ident code, aligning on parens, assignments, etc
Align on '=' and variable definitions
Align structure initializers
Align #define stuff
Align backslash-newline stuff
Reformat comments (a little bit)
Fix inter-character spacing
Add or remove parens on return ......
ÒªÈà Eclipse ¿ÉÒÔ¿ª·¢ C/C++ ³Ìʽ£¬Òª¹ÒÉÏ CDT ²Å¿ÉÒÔ¡£
Ê×ÏÈÒªÏÂÔØCDT
CDTµÄ×îа汾ÊÇ 3.1.0£¬ËüÖ§³Öeclipse3.2.0£¬ÆäÏÂÔصØÖ·£ºhttp://download3.eclipse.org/tools/cdt/releases/callisto/dist/3.1.0/£¬»òÕßÊǵ½http://www.eclipse.org/cdt/downloads.phpÏÂÔØÆäËü° ......
Technorati ±êÇ©: C++ ÔÎĵØÖ·£ºhttp://www.byvoid.com/blog/c-int64/ ÔÚC/C++ÖУ¬64ΪÕûÐÍÒ»Ö±ÊÇÒ»ÖÖûÓÐÈ·¶¨¹æ·¶µÄÊý¾ÝÀàÐÍ¡£ÏÖ½ñÖ÷Á÷µÄ±àÒëÆ÷ÖУ¬¶Ô64ΪÕûÐ͵ÄÖ§³ÖÒ²ÊDZê×¼²»Ò»£¬ÐÎ̬¸÷Òì¡£Ò»°ãÀ´Ëµ£¬64λÕûÐ͵Ķ¨Ò巽ʽÓÐlong longºÍ__int64Á½ÖÖ(VC»¹Ö§³Ö_int64)£¬¶øÊä³öµ½±ê×¼Êä³ö·½Ê½ÓÐprintf(¡°%lld¡±,a)£¬printf ......
C/C++ Reference
http://www.cppreference.com/
C++ Library Reference
http://www.cplusplus.com/ref/
Standard C++ Library Class Reference at Rogue Wave
http://www.roguewave.com/support/docs/hppdocs/stdref/
Dink ......