Tricks for using fstream to create a new file!

A. if you try to creat a file (that does not priviously exits) to use it for writing and reading using code like "fstream file("new_file",ios::out | ios::in) IT WON' T WORCK!!!!!!.
you have to create the file only for writing fstream file("new_file",ios::out) then close the file file.close() and now you can open it again this time for what ever operation you want , for exaple file.open("new_file",ios::out | ios::in | ios::binary) now it will work.

B.if you want to creat a file (that does not priviously exists) at a cirtain location ( for example "c:\\my_folder\\new_file") again you have to create it first only for writing then close it and after that open it again whit what ever operations. BUT IT WON'T WORCK UNLES THE FOLDER "my_folder" ALLREADY EXISTS .
IF YOU WANT TO CREATE THE HOLE STRUCTURE "\\my_folder\\new_file" you have to create the folder "my_folder" first.
you ca do that using the system()
function , which takes operating system comands . for example the ms-dos comand for creating a folder is "md folder_name" . so to create the forder "my_folder" in "c:\\" you have to call the sistem() function like this system("md c:\\my_folder");
. after you created the folder you can create the file in it using the normal fstream.

No comments:

Post a Comment