переменная 'std :: ofstream outfile' имеет инициализатор, но неполный тип - PullRequest
0 голосов
/ 15 мая 2018

Я уже создал CPP программу для этого, которая создает множество файлов с Dev C ++ , в том числе с Dev C ++, но теперь она показывает ошибку.Мой code специализируется на создании HTML шаблонов, но показывает error.

Это некоторые из моих 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(); 
}

1 Ответ

0 голосов
/ 15 мая 2018

Просто добавьте #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
...