C + + Files

Source: Internet
Author: User

; IO stream input/output streamOfstream Write file stream (out) Buffer->fileIfstream Read file stream (in) File->bufferFStream Read and write file stream (that is, can read and write a certain number of inheritance above the two classes) ostream Standard output streamIStream standard input streamiostream standard input/output stream
; input output stream inheritance diagram
; ofstream Write file stream (text); code#include <fstream>using namespace std; #include <stdio.h>  int main (){//output file stream default textchar szbuf1[]= "Hello";Char szbuf2[]= "World";ofstream fout ("F:\\1.txt");     /* if (!fout.is_open ())return 0;logical Inversion If the function returns a result that is not true, it will not really change the value of the returned result return 0    arithmetic inversion ~ Data bitwise inverse RESULTS    */if (!fout.is_open ())return 0;//from BUF to Fout output stream Endl commit buffer to filefout<<szbuf1<<endl;fout<<szbuf2<<endl;//fout.flush () Manually submit buffer contents to file//Close pre-commit buffer contents to filefout.close ();return 0;}; ofstream Write file stream (binary); codeofstream fout2 ("F:\\2.txt", ios::out|ios::binary);if (!fout2.is_open ()) {return 0;    }    //write content to file bufferFout2.write (szbuf1,sizeof (SZBUF1));//Submit buffer contents and close write file streamfout2.close ();; ifstream input file stream file->buffer; streaming Istringstream The meaning of a string as a file, it doesn't work.

C + + Files

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.