C / C ++ filled pit notes - preprocessor and standard library && object-oriented class library

Daily fill hole ......

table of Contents

Preprocessor

Macro parameters

# Operators

Operator ##

Common predefined macros

C ++ Standard Library

C ++ object-oriented class library

reference:


Preprocessor

Macro parameters

I remember when I was a freshman on the machine so the writing was also a teacher gg ......


#include <iostream>
using namespace std;
 
#define MIN(a,b) (a<b ? a : b)
 
int main ()
{
   int i, j;
   i = 100;
   j = 30;
   cout <<"较小的值为:" << MIN(i, j) << endl;
 
    return 0;
}

When the above code is compiled and executed, it produces the following results:

Smaller values: 30

# Operators

# Operator will convert the token replacement-text string with quotation marks.

He said the man, then, is #x string representation x

example:


#include <iostream>
using namespace std;
 
#define MKSTR( x ) #x
 
int main ()
{
    cout << MKSTR(HELLO C++) << endl;
 
    return 0;
}

Output:

HELLO C++

Operator ##

## operator for connecting two tokens.

He said the man, then, is a string that represents x ## y xy even up.

example:


#include <iostream>
using namespace std;
 
#define concat(a, b) a ## b
int main()
{
   int xy = 100;
   
   cout << concat(x, y);
   return 0;
}

Output: 100

The benefits of # ## and written so where? Personally I feel little benefit, or will not use very little? Possible advantage is better for compatibility notes of integer and character?

Common predefined macros

When debugging relatively easy to use! Although there are other libraries can be used, but certainly not easy to use ah macro definition

Macros description
__LINE__ This will include the current line number in the program compile time.
__FILE__ This will include the current file name in the program compile time.
__DATE__ This form contains a string of month / day / year, which represents the source file to convert object code date.
__TIME__ This will include a form of hour: minute: second string that represents the time the program is compiled.

 example:

#include <iostream>
using namespace std;
 
int main ()
{
    cout << "Value of __LINE__ : " << __LINE__ << endl;
    cout << "Value of __FILE__ : " << __FILE__ << endl;
    cout << "Value of __DATE__ : " << __DATE__ << endl;
    cout << "Value of __TIME__ : " << __TIME__ << endl;
 
    return 0;
}

When the above code is compiled and executed, it produces the following results:

Value of __LINE__ : 6
Value of __FILE__ : test.cpp
Value of __DATE__ : Feb 10 2020
Value of __TIME__ : 18:52:48

C ++ Standard Library

  • The input / output I / O
  • And character string processing
  • mathematics
  • Time, date and localization
  • Dynamic allocation
  • other
  • Wide character function

C ++ object-oriented class library

  • Standard C ++ I / O class
  • String class
  • Value classes
  • STL containers
  • STL algorithms
  • STL function objects
  • STL iterators
  • STL allocator
  • Localization Library
  • Exception class
  • Miscellaneous Support Library

reference:

https://www.runoob.com/cplusplus/cpp-preprocessor.html

https://www.runoob.com/cplusplus/cpp-standard-library.html

发布了287 篇原创文章 · 获赞 297 · 访问量 12万+

Guess you like

Origin blog.csdn.net/qq_41895747/article/details/104192633