在include指令中使用尖括号和引号有什么区别?
#包括<文件名>#包括“文件名”
在include指令中使用尖括号和引号有什么区别?
#包括<文件名>#包括“文件名”
当前回答
#include "filename" // User defined header
#include <filename> // Standard library header.
例子:
这里的文件名是Seller.h:
#ifndef SELLER_H // Header guard
#define SELLER_H // Header guard
#include <string>
#include <iostream>
#include <iomanip>
class Seller
{
private:
char name[31];
double sales_total;
public:
Seller();
Seller(char[], double);
char*getName();
#endif
在类实现中(例如,Seller.cpp,以及将使用文件Seller.h的其他文件中),现在应该包含用户定义的头,如下所示:
#include "Seller.h"
其他回答
在C++中,以两种方式包含文件:
第一个是#include,它告诉告诉在预定义的默认位置查找文件。此位置通常是INCLUDE环境变量,表示包含文件的路径。
第二种类型是#include“filename”,它告诉预处理器首先在当前目录中查找文件,然后在用户设置的预定义位置查找文件。
#include "filename" // User defined header
#include <filename> // Standard library header.
例子:
这里的文件名是Seller.h:
#ifndef SELLER_H // Header guard
#define SELLER_H // Header guard
#include <string>
#include <iostream>
#include <iomanip>
class Seller
{
private:
char name[31];
double sales_total;
public:
Seller();
Seller(char[], double);
char*getName();
#endif
在类实现中(例如,Seller.cpp,以及将使用文件Seller.h的其他文件中),现在应该包含用户定义的头,如下所示:
#include "Seller.h"
“<filename>”在标准C库位置搜索而“filename”也会在当前目录中搜索。
理想情况下,您可以使用<…>对于标准C库,“…”表示您编写的当前目录中的库。
在引用系统文件时使用#include<filename>。这是一个头文件,可以在系统默认位置(如/usr/include或/usr/local/include)找到。对于需要包含在其他程序中的自己的文件,必须使用#include“filename”语法。
#include <abc.h>
用于包含标准库文件。因此编译器将检查标准库头所在的位置。
#include "xyz.h"
将告诉编译器包含用户定义的头文件。因此编译器将在当前文件夹或-I定义的文件夹中检查这些头文件。