Read and write files for [C + + language Basics]

Source: Internet
Author: User

1. Open and close the file:

file* fp = fopen (String.c_str (), FLAG);
    • STRING.C_STR (): Requires C-language string form;
    • Flag Description:
      • R: Read-only mode open;
      • W: Write-only mode open;
      • A: Open by append mode;
      • r+: Open in read/write mode; (No files: error)
      • w+: Open in read/write mode; (no files: new)
int fclose (file* fp);
    • Success: returns 0;
    • Failure: Returns EOF;
2. Read and Write files:
    • N-1 characters are read from the stream, unless a line is read, the parameter S is to receive the string, and if successful returns a pointer to s, otherwise null

3. End of file test: int feof (*FP);
The end of the currently reached file returns non 0, otherwise returns 0

Using the FStream method:

1. Include Header files:

#include <fstream>ofstream         //File write operation memory writes to storage device Ifstream         //file read operation, storage device read to memory FStream          

2. Open the file:

void Open (const char * filename, Ios_base::openmode mode = Ios_base::in | ios_base::out); void open (const wchar_t *_file Name, Ios_base::openmode mode= ios_base::in | ios_base::out, int prot = Ios_base::_openprot);

  

Read and write files for [C + + language Basics]

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.