03 2013 档案
摘要:File OperationsFormatted OutputFormatted InputCharacter Input and Output FunctionsDirect Input and Output FunctionsFile Positioning FunctionsError Functions
阅读全文
摘要:The header <limits.h> defines constants for the sizes of integral types.The values below are acceptable minimum magnitudes; larger values may beused.CHAR_BIT 8 bits in a charCHAR_MAX UCHAR_MAX orSCHAR_MAXmaximum value of charCHAR_MIN 0 or SCHAR_MIN maximum value of charINT_MAX 32767 maximum va
阅读全文
摘要:The header <time.h> declares types and functions for manipulating date and time. Somefunctions process local time, which may differ from calendar time, for example because of timezone. clock_t and time_t are arithmetic types representing times, and struct tm holds thecomponents of a calendar t
阅读全文
摘要:9 Signals: <signal.h>The header <signal.h> provides facilities for handling exceptional conditions that arise duringexecution, such as an interrupt signal from an external source or an error in execution.void (*signal(int sig, void (*handler)(int)))(int)signal determines how subsequent s
阅读全文
摘要:The declarations in <setjmp.h> provide a way to avoid the normal function call and returnsequence, typically to permit an immediate return from a deeply nested function call.int setjmp(jmp_buf env)The macro setjmp saves state information in env for use by longjmp. The return iszero from a dire
阅读全文
摘要:7 Variable Argument Lists: <stdarg.h>The header <stdarg.h> provides facilities for stepping through a list of function arguments ofunknown number and type.Suppose lastarg is the last named parameter of a function f with a variable number ofarguments. Then declare within f a variable of t
阅读全文
摘要:The assert macro is used to add diagnostics to programs:void assert(int expression)If expression is zero whenassert(expression)is executed, the assert macro will print on stderr a message, such asAssertion failed: expression, file filename, line nnnIt then calls abort to terminate execution. The sou
阅读全文
摘要:5 Utility Functions: <stdlib.h>The header <stdlib.h> declares functions for number conversion, storage allocation, andsimilar tasks. double atof(const char *s)atof converts s to double; it is equivalent to strtod(s, (char**)NULL).int atoi(const char *s)converts s to int; it is equivalent
阅读全文
摘要:4 Mathematical Functions: <math.h>The header <math.h> declares mathematical functions and macros.The macros EDOM and ERANGE (found in <errno.h>) are non-zero integral constants that areused to signal domain and range errors for the functions; HUGE_VAL is a positive double value.A d
阅读全文
摘要:3 String Functions: <string.h>There are two groups of string functions defined in the header <string.h>. The first havenames beginning with str; the second have names beginning with mem. Except for memmove,the behavior is undefined if copying takes place between overlapping objects. Comp
阅读全文
摘要:2 Character Class Tests: <ctype.h>The header <ctype.h> declares functions for testing characters. For each function, theargument list is an int, whose value must be EOF or representable as an unsigned char, andthe return value is an int. The functions return non-zero (true) if the argume
阅读全文
摘要:1.7 Error FunctionsMany of the functions in the library set status indicators when error or end of file occur. Theseindicators may be set and tested explicitly. In addition, the integer expression errno (declaredin <errno.h>) may contain an error number that gives further information about the
阅读全文
摘要:1.6 File Positioning Functionsint fseek(FILE *stream, long offset, int origin)fseek sets the file position for stream; a subsequent read or write will access databeginning at the new position. For a binary file, the position is set to offset charactersfrom origin, which may be SEEK_SET (beginning),
阅读全文
摘要:1.5 Direct Input and Output Functionssize_t fread(void *ptr, size_t size, size_t nobj, FILE *stream)fread reads from stream into the array ptr at most nobj objects of size size. freadreturns the number of objects read; this may be less than the number requested. feofand ferror must be used to determ
阅读全文
摘要:1.4 Character Input and Output Functionsint fgetc(FILE *stream)fgetc returns the next character of stream as an unsigned char (converted to anint), or EOF if end of file or error occurs.char *fgets(char *s, int n, FILE *stream)fgets reads at most the next n-1 characters into the array s, stopping if
阅读全文
摘要:Formatted InputThe scanf function deals with formatted input conversion.int fscanf(FILE *stream, const char *format, ...)fscanf reads from stream under control of format, and assigns converted values throughsubsequent arguments, each of which must be a pointer. It returns when format is exhausted.fs
阅读全文
摘要:Formatted OutputThe printf functions provide formatted output conversion.int fprintf(FILE *stream, const char *format, ...)fprintf converts and writes output to stream under the control of format. The return valueis the number of characters written, or negative if an error occurred.int printf(const
阅读全文
摘要:File OperationsThe following functions deal with operations on files. The type size_t is the unsigned integraltype produced by the sizeof operator.FILE *fopen(const char *filename, const char *mode)fopen opens the named file, and returns a stream, or NULL if the attempt fails. Legalvalues for mode i
阅读全文
摘要:C/C++对时间的操作也有许多值得大家注意的地方。最近,在技术群中有很多网友也多次问到过C++语言中对时间的操作、获取和显示等等的问题。下面,在这篇文章中,笔者将主要介绍在C/C++中时间和日期的使用方法. 通过学习许多C/C++库,你可以有很多操作、使用时间的方法。但在这之前你需要了解一些“时间”和“日期”的概念,主要有以下几个: Coordinated Universal Time(UTC):协调世界时,又称为世界标准时间,也就是大家所熟知的格林威治标准时间(Greenwich Mean Time,GMT)。比如,中国内地的时间与UTC的时差为+8,也就是UTC+8。美国是UTC-5。 C
阅读全文
摘要:all_ofReturns true when a condition is present at each element in the given range.template<class InputIterator, class Predicate> bool all_of( InputIterator _First, InputIterator _Last, BinaryPredicate _Comp );any_ofReturns true when a condition is present at least once i...
阅读全文
摘要:inplace_mergeCombines the elements from two consecutive sorted ranges into a single sorted range, where the ordering criterion may be specified by a binary predicate.template<class BidirectionalIterator> void inplace_merge( BidirectionalIterator _First, BidirectionalIterator _Middle, ...
阅读全文
摘要:sortArranges the elements in a specified range into a nondescending order or according to an ordering criterion specified by a binary predicate.template<class RandomAccessIterator> void sort( RandomAccessIterator first, RandomAccessIterator last );template<class RandomAccessIterator, ...
阅读全文
摘要:random_shuffleRearranges a sequence of N elements in a range into one of N! possible arrangements selected at random.template<class RandomAccessIterator> void random_shuffle( RandomAccessIterator _First, RandomAccessIterator _Last ); template<class RandomAccessIterator, class Rand...
阅读全文
摘要:next_permutationReorders the elements in a range so that the original ordering is replaced by the lexicographically next greater permutation if it exists, where the sense of next may be specified with a binary predicate.template<class BidirectionalIterator> bool next_permutation( Bidirectio...
阅读全文
摘要:uniqueRemoves duplicate elements that are adjacent to each other in a specified range.template<class ForwardIterator> ForwardIterator unique( ForwardIterator _First, ForwardIterator _Last );template<class ForwardIterator, class Predicate> ForwardIterator unique( ForwardIterator...
阅读全文
摘要:transformApplies a specified function object to each element in a source range or to a pair of elements from two source ranges and copies the return values of the function object into a destination range.template<class InputIterator, class OutputIterator, class UnaryFunction> OutputIterator tr
阅读全文
摘要:rotateExchanges the elements in two adjacent ranges.template<class ForwardIterator> void rotate( ForwardIterator _First, ForwardIterator _Middle, ForwardIterator _Last );rotate_copyExchanges the elements in two adjacent ranges within a source range and copies the result to ...
阅读全文
摘要:reverseReverses the order of the elements within a range.template<class BidirectionalIterator> void reverse( BidirectionalIterator _First, BidirectionalIterator _Last );reverse_copyReverses the order of the elements within a source range while copying them into a destination range...
阅读全文
摘要:replaceExamines each element in a range and replaces it if it matches a specified value.template<class ForwardIterator, class Type> void replace( ForwardIterator _First, ForwardIterator _Last, const Type& _OldVal, const Type& _NewVal );replace_ifExamines each element ...
阅读全文
摘要:removeEliminates a specified value from a given range without disturbing the order of the remaining elements and returning the end of a new range free of the specified value.template<class ForwardIterator, class Type> ForwardIterator remove( ForwardIterator _First, ForwardIterator _L...
阅读全文
摘要:partitionClassifies elements in a range into two disjoint sets, with those elements satisfying a unary predicate preceding those that fail to satisfy it.template<class BidirectionalIterator, class Predicate> BidirectionalIterator partition( BidirectionalIterator _First, BidirectionalIte...
阅读全文
摘要:mergeCombines all of the elements from two sorted source ranges into a single, sorted destination range, where the ordering criterion may be specified by a binary predicate.template<class InputIterator1, class InputIterator2, class OutputIterator> OutputIterator merge( InputIterator1 _First...
阅读全文
摘要:汇总打印集合的方法1. for_eachtemplate<class T>struct display{ void operator()(const T& val){ cout<<val<<' '; }};int main(){ vector<int> vec(10); iota(vec.begin(),vec.end(),1); random_shuffle(vec.begin(),vec.end()); for_each(vec.begin(),vec.end(),display<int>()); cout
阅读全文
摘要:for_eachApplies a specified function object to each element in a forward order within a range and returns the function object.template<class InputIterator, class Function> Function for_each( InputIterator _First, InputIterator _Last, Function _Func );
阅读全文
摘要:includesTests whether one sorted range contains all the elements contained in a second sorted range, where the ordering or equivalence criterion between elements may be specified by a binary predicate.template<class InputIterator1, class InputIterator2> bool includes( InputIterator1 _First1...
阅读全文
摘要:countReturns the number of elements in a range whose values match a specified value.template<class InputIterator, class Type> typename iterator_traits<InputIterator>::difference_type count( InputIterator _First, InputIterator _Last, const Type& _Val );count_ifReturns the number ...
阅读全文
摘要:adjacent_findSearches for two adjacent elements that are either equal or satisfy a specified condition.即,找出第一组满足条件的相邻元素。template<class ForwardIterator> ForwardIterator adjacent_find( ForwardIterator _First, ForwardIterator _Last );template<class ForwardIterator , class BinaryPredicate...
阅读全文
摘要:make_heapConverts elements from a specified range into a heap in which the first element is the largest and for which a sorting criterion may be specified with a binary predicate.template<class RandomAccessIterator> void make_heap( RandomAccessIterator _First, RandomAccessIterator _Last...
阅读全文
摘要:本节的四个算法所接受的set,必须是有序区间(sorted range),元素值可以重复出现。也就是说,他们可以接受STL的set/multiset容器作为输入区间。set_unionUnites all of the elements that belong to at least one of two sorted source ranges into a single, sorted destination range, where the ordering criterion may be specified by a binary predicate.template<clas
阅读全文
摘要:二分查找binary_searchTests whether there is an element in a sorted range that is equal to a specified value or that is equivalent to it in a sense specified by a binary predicate.template<class ForwardIterator, class Type> bool binary_search( ForwardIterator _First, ForwardIterator _Last, ...
阅读全文
摘要:copyAssigns the values of elements from a source range to a destination range, iterating through the source sequence of elements and assigning them new positions in a forward direction.template<class InputIterator, class OutputIterator> OutputIterator copy( InputIterator _First, InputIt...
阅读全文
摘要:mismatchCompares two ranges element by element either for equality or equivalent in a sense specified by a binary predicate and locates the first position where a difference occurs.template<class InputIterator1, class InputIterator2> pair<InputIterator1, InputIterator2> mismatch( InputIt
阅读全文
摘要:maxCompares two objects and returns the larger of the two, where the ordering criterion may be specified by a binary predicate.template<class Type> const Type& max( const Type& _Left, const Type& _Right );template<class Type, class Pr> const Type& max( const Type& _Le
阅读全文
摘要:lexicographical_compareCompares element by element between two sequences to determine which is lesser of the two.(以字典排列方式进行比较)template<class InputIterator1, class InputIterator2> bool lexicographical_compare( InputIterator1 _First1, InputIterator1 _Last1, InputIterator2 _First2, ...
阅读全文
摘要:iter_swapExchanges two values referred to by a pair of specified iterators.template<class ForwardIterator1, class ForwardIterator2> void iter_swap( ForwardIterator1 _Left, ForwardIterator2 _Right );这个好像没有什么特别的,就是交换两个迭代器所指向的内容。swapThe first override exchanges the values of two objects. ...
阅读全文
摘要:fillAssigns the same new value to every element in a specified range.template<class ForwardIterator, class Type> void fill( ForwardIterator _First, ForwardIterator _Last, const Type& _Val );fill_nAssigns a new value to a specified number of elements in a range beginning with a p...
阅读全文
摘要:equalCompares two ranges element by element either for equality or equivalence in a sense specified by a binary predicate.template<class InputIterator1, class InputIterator2> bool equal( InputIterator1 _First1, InputIterator1 _Last1, InputIterator2 _First2 );template<class Input...
阅读全文
摘要:<numeric>:Defines container template functions that perform algorithms provided for numerical processing.accumulateComputes the sum of all the elements in a specified range including some initial value by computing successive partial sums or computes the result of successive partial results si
阅读全文
摘要:1.递归实现int binarySearchRecursive(int a[],int low,int high,int key){ if(low>high) return -(low+1); int mid=low+(high-low)/2; if(key<a[mid]) return binarySearchRecursive(a,low,mid-1,key); else if(key > a[mid]) return binarySearchRecursive(a,mid+1,high,key); else ...
阅读全文

浙公网安备 33010602011771号