c++ - 变量“std::ofstream outfile”具有初始化程序但类型不完整
问题描述
我已经为此编写了一个程序,它使用Dev C++CPP
创建了很多文件,这个也是使用 Dev C++ 的,但现在它显示错误。My专门用于创建模板,但它显示.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();
}
解决方案
只需添加#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
推荐阅读
- c# - 如何正确请求 Azure 不记名令牌或为什么要求我发送“范围”参数?
- java - 在适用于 android 和 ios 的 Flutter 应用中应用深度链接
- android - No callback for startActivityForResult in case of MediaStore.INTENT_ACTION_VIDEO_CAMERA
- android - Exception handling of network errors retrofit
- google-sheets - Finding closest greater from a filtered range
- python - Getting the column "number" and column name to make it easier to select several - not always adjacent - columns in a large df in pandas
- javafx - 在javafx中绘制箭头形状
- javascript - 是否可以关闭所需的流注释?
- excel - 屏幕更新不会更改为 false
- firebase - 将 Firebase 用户属性更改或删除给特定用户