开发者

Create a file C++ (cross-platform solution for Unix and Windows)

Is there a way from C++ code to use (fstream, FILE, etc.) to create a file on both Unix and Windows?

If not what you can do in order to have your code run on b开发者_如何学运维oth Unix and Windows?


ofstream out(path);

or

FILE *fp = fopen(path, "w");

will create the file path if it does not exist.


fopen("foo.txt", "w"); // write-only
fopen("foo.txt", "w+"); // write+read
fstream filestr;
filestr.open ("foo.txt", fstream::out | fstream::trunc); // write-only
filestr.open ("foo.txt", fstream::in | fstream::out | fstream::trunc); // write+read

All of these will create the file, or truncate it if it already exists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜