C++: Create a File

Bjarne-stroustrup
 

In this task, the job is to create a new empty file called “output.txt” of size 0 bytes and an empty directory called “docs”. This should be done twice: once “here”, i.e. in the current working directory and once in the filesystem root.

#include <fstream>
#include <direct.h>

int main() {
	std::fstream f( "output.txt", std::ios::out );
	f.close();
	f.open( "/output.txt", std::ios::out );
	f.close();

	_mkdir( "docs" );
	_mkdir( "/docs" );

	return 0;
}

SOURCE

Content is available under GNU Free Documentation License 1.2.