本文介绍了ofstream不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ofstream myfile;
myfile.open("C:\\example.txt", ofstream::out);
//doesn't create the file and myfile.is_open() returns false
myfile << "Writing this to a file.\n";
myfile.close();
}
当你需要提出这类问题时,这有点令人沮丧。
在Windows控制台应用程序中,如果我提供无路径,则ofstream不会在给定位置创建任何文件,但是,确实如此。
无论我是否使用构造函数或open函数,仍然无法正常工作
It's kinda frustrating when you have the need to ask questions of this kind.
Here it is, on a windows console application, ofstream is not creating any file at the given location, if I supply no-path, however, it does.
No matter if I use the constructor or the open function, still doesn't work
推荐答案
这篇关于ofstream不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!