C++ Директиви препроцесора

2075 / C++ / Додатково / Директиви препроцесора

Макроси

cout << __LINE__ << endl;
cout << __FILE__ << endl;
cout << __func__ << endl;
cout << __DATE__ << endl;
7
c:\users\andreo\documents\visual studio 2015\projects\project46\project46\source.cpp
main
May 15 2025
#define PI 3.14
#define FOO(x,y) (x + y)
#define begin {
#define end }
#define n "\n"

cout << PI << endl;
cout << FOO(3, 4) << endl; 
if (5 > 2)
begin
  cout << n << "ok" << endl;
end
3.14
7
.
ok

 

#undef FOO – скасувати дію директиви