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");
   exit(1);
}

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");
    exit(1);
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.