第一章 00 StringUtil.cpp和StringUtil.hh分析

 1 /*
 2  * StringUtil.hh
 3  *
 4  * Copyright 2002, Log4cpp Project. All rights reserved.
 5  *
 6  * See the COPYING file for the terms of usage and distribution.
 7  */
 8 头文件的说明,以及与版权相关的说明一般都会放置在文件的开始位置


9 #ifndef _LOG4CPP_STRINGUTIL_HH //为了防止代码被多重包含 10 #define _LOG4CPP_STRINGUTIL_HH 11 12 #include "PortabilityImpl.hh" 13 #include <string> 14 #include <vector> 15 #include <climits> 16 #include <stdarg.h> 17 18 namespace log4cpp { 19 20 class StringUtil { 21 public: 22 23 /** 24 Returns a string contructed from the a format specifier 25 and a va_list of arguments, analogously to vprintf(3). 26 @param format the format specifier. 27 @param args the va_list of arguments. 28 **/ 29 static std::string vform(const char* format, va_list args); 30 31 /** 32 Returns a string identical to the given string but without leading 33 or trailing HTABs or spaces. 34 **/ 35 static std::string trim(const std::string& s); 36 37 /** 38 splits a string into a vector of string segments based on the 39 given delimiter. 40 @param v The vector in which the segments will be stored. The vector 41 will be emptied before storing the segments 42 @param s The string to split into segments. 43 @param delimiter The delimiter character 44 @param maxSegments the maximum number of segments. Upon return 45 v.size() <= maxSegments. The string is scanned from left to right 46 so v[maxSegments - 1] may contain a string containing the delimiter 47 character. 48 @return The actual number of segments (limited by maxSegments). 49 **/ 50 static unsigned int split(std::vector<std::string>& v, 51 const std::string& s, char delimiter, 52 unsigned int maxSegments = INT_MAX); 53 /** 54 splits a string into string segments based on the given delimiter 55 and assigns the segments through an output_iterator. 56 @param output The output_iterator through which to assign the string 57 segments. Typically this will be a back_insertion_iterator. 58 @param s The string to split into segments. 59 @param delimiter The delimiter character 60 @param maxSegments The maximum number of segments. 61 @return The actual number of segments (limited by maxSegments). 62 **/ 63 template<typename T> static unsigned int split(T& output, 64 const std::string& s, char delimiter, 65 unsigned int maxSegments = INT_MAX) { 66 std::string::size_type left = 0; 67 unsigned int i; 68 for(i = 1; i < maxSegments; i++) { 69 std::string::size_type right = s.find(delimiter, left); 70 if (right == std::string::npos) { 71 break; 72 } 73 *output++ = s.substr(left, right - left); 74 left = right + 1; 75 } 76 77 *output++ = s.substr(left); 78 return i; 79 } 80 }; 81 } 82 83 #endif // _LOG4CPP_STRINGUTIL_HH


一、关于#include的话题
#include <iostream>
#include <iostream.h>
两行代码有什么区别呢
 1 #include <iostream.h>
 2 
 3 using namespace std;
 4 
 5 int main(int argc,char**argv)
 6 {
 7    cout<<"hi guys"<<endl;
 8         
 9   return 0;   
10 }

编译器会发出报警哦:


看来是C++标准的问题,新的代码逐渐不再支持<X.h>的包含方式,但是该警告信息可以在编译器中用-Wno-deprecated选项关闭的。deprecated这里的意思是“过时了”

至于是否在头文件中要用include包含头文件,这个可以开新的话题了,留待以后补上吧。。。。。
嗯哼。。。LINE16还没解释,为毛????
stdarg.h是C语言中C标准函数库的头文件,stdarg是由standard(标准) arguments(参数)简化而来,主要目的为让函数能够接收可变参数。
C++的cstdarg头文件中也提供这样的功能;虽然与C的头文件是兼容的,但是也有冲突存在。

这里引出了两个标准函数库:C标准函数库和C++标准函数库。额,这也是两个巨大的Topics,还是度娘吧。。。。。由于这里引用了C标准函数库的头文件,
So,用了#include <stdargs.h>的写法。至于。。。至于哪个头文件属于C++标准函数库,哪个属于C标准函数库呢,Windows平台的IDE开发环境发挥了积极的优势。
See See吧,

自动补齐功能,提示的是.h文件哦。。。。


这个是没有.h的。
好了,不要在这个话题上纠结了。Go on .......睡觉鸟。。。。。


























 

posted @ 2014-12-01 00:01  鱼跃与渊  阅读(298)  评论(0编辑  收藏  举报