IO Standard library types and header files

iostream istream Read from stream
ostream Write in the stream
iostream Read and write to the stream ; from istream and ostream Derived from
fstream ifstream Read from file ; from istream Derived from
ofstream Write it in the file ; from ostream Derived from
fstream Read and write files ; from iostream Derived from
sstream istringstream from string Object ; from istream Derived from
ostringstream writes string Go to the object ; from ostream Derived from
stringstream Yes string Object to read and write ; from iostream Derived from

1 When a file stream object is used again, it is necessary to first clear

ifstream& open_file(ifstream &in, const string &file)
in.close(); // close in case it was already open
in.clear(); // clear any existing errors
// if the open fails, the stream will be in an invalid state; // open the file we were given
return in; // condition state is good if open succeeded

2 Check object status when opening a file

ifstream input;
vector<string>::const_iterator it = files.begin();
// for each file in the vector
while (it != files.end()) {>c_str()); // open the file
// if the file is ok, read and "process" the input
if (!input)
break; // error: bail out!
while(input >> s) // do the work on this file
input.close(); // close file when we're done with it
input.clear(); // reset state to ok
++it; // increment iterator to get next file

3 File open mode combination

out Open the file for writing , Delete the existing data in the file
out | app Open the file for writing , Write... At the end of the file
out | trunc And out Same pattern
in Open the file for reading
in | out Open the file to read 、 Write operations , And set it at the beginning of the file
in | out | trunc Open the file to read 、 Write operations , Delete the existing data in the file

C++Primer,C++ standard IO Library to read more about the experience of the article

  1. C++ Primer Reading notes : The first 8 Chapter standard IO library

    The first 8 Chapter standard IO library 8.1 Object oriented standard library 1. IO Types are defined in three separate header files :iostream Define the type of read / write control window ,fstream Defines the type of reading and writing named files , and sstream The defined type is used for ...

  2. c++ primer Notes on learning 3【 standard IO library 】

    The first 8 Chapter standard IO library Found a mistake in the book , Chinese version p248 Query and control of flow state , Take a code example : int ival; // read cin and test only for EOF; loop is ...

  3. [APUE] standard IO library ( Next )

    One . standard IO The efficiency of Compare the users of the following four programs CPU. System CPU Compared with clock time Program 1: System IO Program 2: standard IO getc edition Program 3: standard IO fgets edition result : [ notes : The table is intercepted from APUE, The above table ...

  4. [APUE] standard IO library ( On )

    One . Flow and FILE object System IO It's all about file descriptors , When opening a file , That is to return a file descriptor , Then use the file descriptor to do the following , And for standards IO library , They operate around the flow (stream) On going . When you open a ...

  5. file IO Functions and standards IO The difference between Libraries

    Excerpt from 1, file IO function , stay Unix in , There are the following 5 individual :open,read,write,lsee ...

  6. senior UNIX Environment programming 5 standard IO library

    standard IO It's all about flow in <stdio.h><wchar.h> memccpy It's usually written in assembly ftell/fseek/ftello/fseeko/fgetpos/fsetp ...

  7. 18、 standard IO Library details and examples

    standard IO The library was created by Dennis Ritchie On 1975 It was written in about 2000 , It is Mike Lestbain It's portable IO Major modified versions of the library ,2010 Years later , standard IO There are few changes to the library . standard IO The library handles a lot of detail ...

  8. Chapter 13 : With buffer IO( standard IO library )

    Preface Before , To study the read write This one doesn't have a buffer IO function . And this article will talk about standards IO In the library , With buffer IO function . Why should there be a buffer IO function The standard library provides buffering IO Function is to reduce read and wri ...

  9. C5 standard IO library :APUE note

    C5 : standard IO library In chapter three , all IO Functions are expanded around file descriptors , File descriptors are used for subsequent IO operation . Since file descriptor related operations are not buffered IO, The operator is required to specify the buffer allocation .IO Length etc. , The environment of the equipment requires certain ...

Random recommendation

  1. python operation SQL

    pymysql pymsql yes Python In the operation MySQL Module , How to use it and MySQLdb Almost the same One . Download and install pip3 install pymysql Two . Operation and use 1. perform SQL #!/usr ...

  2. The first 20 Chapter CSS3 The prefix and rem

    Learning points : 1.CSS3 Prefix 2. A unit of length  rem The lecturer : Li Yanhui This chapter mainly discusses HTML5  in CSS  Some problems in implementing standardization in development , Focus on CSS3  New attribute prefix problem and new unit rem. One ...

  3. C# Read Excel

    Add code directly : public void connExcel(string strPath) { //string strConn = @"Provider=Microsoft.Jet.OLED ...

  4. 5 Minute comprehension iaas paas saas The difference between the three cloud services

    With the popularity of Cloud Computing , More and more children's shoes are asking me about cloud computing , One of the more frequently asked questions recently is in cloud computing pass What does that mean? ? I'm free today , Let's give you a unified explanation pass What does that mean? ? and Iass.Sass What's going on between ...

  5. learn OpenGL Some good websites of

    There are too many good resources , I know too little , Now step forward from the beginning !!fighting...... some OpenGL Resource link Here are a few links I sorted out a few days ago , I hope you found that useful By the way http://www.spacesim ...

  6. GitHub And VS2013 Complete project management Programmers should go to a website with an account 1. Create a warehouse Log in to your github Website : Find the entrance to a new warehouse After filling in some basic information , Click Create , You can have a warehouse 2. Give Way V ...

  7. Oracle Sequence (sequence)

    Sequence is Oracle Peculiar , He can maintain a sequence of self increasing numbers , Usually from 1 Start to grow , But you can set . (1) Create sequence : increment (2) Usage sequence : insert into student(sno,name ...

  8. linux Next Mysql Installation 、 To configure 、 Data import and export

    MySQL Is an open source relational database management system (RDBMS), Although it may not be very powerful , But it's popular because it's free and open source . This time, , Next to the last one <CentOs minimal Installation and development environment deployment >, Talk a L ...

  9. JAVA Calculate the difference between the two times in God , when , branch , second

    1: import java.util.Date; 2: 3: public class ShowTimeInterval{ 4: public void ShowTimeInterval(Date ...

  10. [HNOI2016] Large number

    Title Description Small B There's a big number S, The length has reached N position : This number can be seen as a string , It may have a lead 0, for example 00009312345. Small B There is also a prime number P. Now? , Small B Put forward M A asked , Every inquiry asks for S Of ...