fstream无法创建txt [英] fstream cant create txt

查看:107
本文介绍了fstream无法创建txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
#include<fstream>

using namespace std;
int main(){

ifstream inputFile;
ofstream outputFile;

inputFile.open ("DataIn.txt");
inputFile.close();
}



上面的代码没有错误运行,但是不会创建DataIn.txt.
我的代码有什么问题吗?



The above code run with no error,but it doesnt create the DataIn.txt.
Anything wrong with my code?

推荐答案

您正在尝试打开输入文件,这意味着如果文件不存在,则打开将失败,它不会创建该文件.查看 ifstream [
You are trying to open an input file which means the open will fail if the file does not exist, it does not create it. Take a look at the documentation for ifstream[^], and ofstream while you are there.


您已使用#include两次,但未指定任何文件.
删除这些"#include"行.然后在其中输入#include< fstream.h>.
我希望这能奏效.
祝你好运.
You have used #include two times but you did not specify any file.
Remove these "#include" lines. And type there #include <fstream.h>.
I hope this works.
GOOD LUCK.


这篇关于fstream无法创建txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆