C/C++ (Window) Create / Open / Read / Write a File

1.Open a file for READ ONLY
int src_fld = open("C:\test.txt", O_RDONLY);//open function return a unique int as the handle for the file
if (src_fld == -1) {
   printf("Cannot find test1.txt file.\n");

2.Create a file and write into
int dst_fld = open("C:\test2.txt", O_CREAT | O_WRONLY);
if (dst_fld == -1) {
    printf("Cannot create test2.txt file.\n");

Add Comment