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 .......睡覺鳥。。。。。
?