C + + file operation learning

Source: Internet
Author: User

    1. FStream The ability to read and write text
    2. ostream can only write to text
    3. IStream can only read text

Let 's take a look at the member functions of the Stream class libraryput (char c) outputs one characterWrite (const char * str,int N) outputs a string Get (char c) gets a charactergetline (char *buf,int n,char deline= ' \ n ') reads a line of characters the last parameter is the terminating flag characterRead (char *buf, int n) reads a number of characters Ios::in Read OnlyIos::out only outIos::app Appendios::ate at end of file when openIos::trunc If there is a file then empty, not exist then createios::binary opens in binary mode ------------------------------------the best way to profile is-----------------------------------writes written out of file stream pairs
  1. int a;
  2. string str;
  3. istream file("123.txt",ios::in|ios::out);
  4. file>>a;
  5. file>>str;
  6. //如果是写入的话
  7. file<<a;
  8. file<<str;
  9. // 文件流一般是 遇到空格 或者 换行符 就会终止读取



From for notes (Wiz)



C + + file operation learning

Related Article

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.