Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ '的含义\';在#define中使用_C++_Char - Fatal编程技术网

C++ '的含义\';在#define中使用

C++ '的含义\';在#define中使用,c++,char,C++,Char,我想知道代码“\”的含义。我以前看过一些解释,但我忘了,谁能告诉我 #include "stdafx.h" #include <fstream> using namespace std; ofstream out("order.out"); #define CLASS(ID) class ID {\ public: \ ID(int) { out<<#ID " constructor\n;} \ ~ID() { out<< #ID "destr

我想知道代码“\”的含义。我以前看过一些解释,但我忘了,谁能告诉我

#include "stdafx.h"
#include <fstream>
using namespace std;

ofstream out("order.out");

#define CLASS(ID) class ID {\
public: \
   ID(int) { out<<#ID " constructor\n;} \
   ~ID() { out<< #ID "destructor\n";}\
};
#包括“stdafx.h”
#包括
使用名称空间std;
流出来(“order.out”);
#定义类(ID)类ID{\
公众:\

ID(int){out使编译器将当前行和
\
之后的行视为同一行

对于定义,这一点很重要,因为预处理器只考虑当前行上的内容

例如:

#define CLASS(ID) class ID {
public: 
   ID(int) { out<<#ID " constructor\n;} 
   ~ID() { out<< #ID "destructor\n";}
};

CLASS(foo)
鉴于

#define CLASS(ID) class ID {\
public: \
   ID(int) { out<<#ID " constructor\n;} \
   ~ID() { out<< #ID "destructor\n";}\
};

CLASS(foo)
#定义类(ID)类ID{\
公众:\
ID(int){out每行末尾的反斜杠(
\
)表示下一行是当前行的延续

所以

与相同

 #define class(ID) class \
 ID

它是一个反斜杠。当一行代码太大,为了可读性和文档编制需要分成几段时,通常使用反斜杠。它将一行连接到下一行,也可以链接到多行。

它允许您通过将以反斜杠结尾的行与下一行连接来定义多行。

定义
中的
\'
的用法

\
允许您编写多行宏。
\
附加在每行末尾


<>你可以在

上了解更多的信息:这个行的延续不仅仅是针对<代码>定义的< /C> >它几乎是在任何一行上。除了宏定义之外,在大多数情况下,这在C/C++中并不重要(除非你喜欢在标识符的中间有断线)。(并引起一个令人不快的惊喜)是如果在
/
风格的单行注释末尾有一行,那么下一个物理行将被视为注释的一部分。
class foo {
public: 
   foo(int) { out<<"foo" " constructor\n;} 
   ~foo() { out<<"foo" "destructor\n";}
};
#define class(ID) class ID
 #define class(ID) class \
 ID