包含文件不工作 C++
include file not working c++
我创建了一个头文件以包含其他头文件作为快捷方式,它几乎适用于我的所有文件,但我的文件 i/o 文件一直有问题(它抛出有关不正确的错误包括文件)。
包含文件 (includes.h)
#ifndef INCLUDES_H_
#define INCLUDES_H_
#include <vector>
#include "html.h"
#include "file.h"
#include <string>
#include "test.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <cstdlib>
#endif
文件 (file.h)
#ifndef FILE_H_
#define FILE_H_
#include "includes.h"
namespace file
{
int file()
{
std::string filename;
std::cout <<"What would you like to name your file?\n";
std::cout << "(don't put in the .html)\n";
std::cin >> filename;
filename = filename +".html";
std::ofstream outf(filename);
return 0;
}
}
#endif
您不应在 files.h
文件中包含 files.h
。
制作一个庞大的包含文件一般来说似乎不是一个好主意。无论是否实际需要,所有内容始终随处包含。这可能会导致难以诊断错误。
只包含您需要的东西。
我创建了一个头文件以包含其他头文件作为快捷方式,它几乎适用于我的所有文件,但我的文件 i/o 文件一直有问题(它抛出有关不正确的错误包括文件)。
包含文件 (includes.h)
#ifndef INCLUDES_H_
#define INCLUDES_H_
#include <vector>
#include "html.h"
#include "file.h"
#include <string>
#include "test.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <cstdlib>
#endif
文件 (file.h)
#ifndef FILE_H_
#define FILE_H_
#include "includes.h"
namespace file
{
int file()
{
std::string filename;
std::cout <<"What would you like to name your file?\n";
std::cout << "(don't put in the .html)\n";
std::cin >> filename;
filename = filename +".html";
std::ofstream outf(filename);
return 0;
}
}
#endif
您不应在 files.h
文件中包含 files.h
。
制作一个庞大的包含文件一般来说似乎不是一个好主意。无论是否实际需要,所有内容始终随处包含。这可能会导致难以诊断错误。
只包含您需要的东西。