How to perform file operations: Get File Name: Open File: Move file pointer .........

Source: Internet
Author: User
Get the file name {cstring filepathname; cfiledialog DLG (true); // true: Open dialog box, false: Save As dialog box if (DLG. domodal () = idok) filepathname = DLG. getpathname ();} related information: cfiledialog is used to retrieve several member functions of a file name. For example, if the selected file is C:/Windows/test. EXE: (1) getpathname (); takes the full name of the file name, including the complete path. Retrieve C:/Windows/test. EXE (2) getfiletitle (); get the full name of the file: test. EXE (3) getfilename (); Retrieve test (4) getfileext (); Retrieve extension exe
Open the cfile file ("C:/hello. TXT ", cfile: moderead); // open in read-only mode // cfile: moderead can be changed to cfile: modewrite (write only), cfile :: modereadwrite (read/write), cfile: modecreate (new) Example: {cfile file; file. open ("C:/hello. TXT ", cfile: modecreate | cfile: modewrite );......}
Move file pointer file. seek (100, cfile: Begin); // start from the file header and move down the 100-byte file. seek (-50, cfile: End); // move 50 bytes of file from the end of the file. seek (-30, cfile: Current); // move up 30 bytes of file from the current position. seektobegin (); // move to the file header file. seektoend (); // move to the end of the file
Read/write files: Char buffer [1000]; file. read (buffer, 1000); Write File: cstring string ("this world can only succeed if it is paranoid"); file. write (string, 8 );
Close file. Close ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.