首页 > 解决方案 > 变量“std::ofstream outfile”具有初始化程序但类型不完整

问题描述

我已经为此编写了一个程序,它使用Dev C++CPP创建了很多文件,这个也是使用 Dev C++ 的,但现在它显示错误。My专门用于创建模板,但它显示.codeHTMLerror

这是我的一些code

#include <iostream>
using std::cout;
using std::cin;
using std::ofstream;
using std::endl;

void HelloWorld() {
    ofstream outfile ("html1.html");

    outfile << "<html> " << endl;
    outfile << "   <head> <title> Template Hello World </title> </head>" << endl;
    outfile << "   <body> <h1> Hello World! </h1> </body> " << endl;
    outfile << "</html> " << endl;
    outfile << "// Template HTML 2018 " << endl;
    cout << "Created Succesfuly! Directory: Program's folder " << endl;


    outfile.close(); 
}

标签: c++dev-c++

解决方案


只需添加#include <fstream>到您的包含:

#include <iostream>
#include <fstream>
using std::cout;
using std::cin;
using std::ofstream;
using std::endl;

void HelloWorld() {
    ofstream outfile ("html1.html");

    outfile << "<html> " << endl;
    outfile << "   <head> <title> Template Hello World </title> </head>" << endl;
    outfile << "   <body> <h1> Hello World! </h1> </body> " << endl;
    outfile << "</html> " << endl;
    outfile << "// Template HTML 2018 " << endl;
    cout << "Created Succesfuly! Directory: Program's folder " << endl;

    outfile.close();
}

int main()
{
    HelloWorld();
    return 0;
}

输出 :

Created Successfully! Directory: Program's folder

推荐阅读