我只是试图创建一个文本文件,如果它不存在,我似乎无法得到fstream
来做到这一点。fstream不会创建文件
#include <fstream>
using std::fstream;
int main(int argc, char *argv[]) {
fstream file;
file.open("test.txt");
file << "test";
file.close();
}
我需要在open()
功能,以获得它来创建文件中指定什么?我读过,你不能指定ios::in
,因为它会预期现有的文件存在,但我不确定是否需要为尚不存在的文件指定其他参数。
我认为你必须使用:。开( “test.txt的”,fstream的::中) ; – FacundoGFlores 2013-03-27 19:20:01