gpt4 book ai didi

c++ - 包含文件不工作 C++

转载 作者:行者123 更新时间:2023-11-28 04:44:31 25 4
gpt4 key购买 nike

我创建了一个头文件以包含其他头文件作为快捷方式,它几乎适用于我的所有文件,但我的文件 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

文件(文件.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

制作一个庞大的包含文件一般来说似乎不是一个好主意。无论是否实际需要,所有内容始终随处包含。这可能会导致难以诊断错误。

只包含你需要的东西。

关于c++ - 包含文件不工作 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49539386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com