c begin remote starting the journey: (11) class

]
10 cout <<(char) cin.get () < 26 fin.close ();
28}
getline () operation with>> the difference
[oracle @ localhost ~] $ vi seconddisplay.cc
21 fin.close ();
8 cout <<"input 2 chars:";
3 using namespace std ;
2 using namespace std;
19 fout < 2 using namespace std;
3 # include
9 cout << cin.get () < 18 char ch = 0

n = 123
14
3
14 cout <<" input a line (<20): ";
d = 31.5
9 cin.get (b);
4 # include
7 {
char string1 [256]
[oracle @ localhost ~] $ g seconddisplay.cc
[oracle @ localhost ~] $ g char.cc
25 cout <<"ch =" < 123
cin>> name; cin>> name;
26}
~ [oracle @ localhost ~] $ vi file.cc
15 char ch;
cin.ignore ();
22
97
19
2 # include
if (! fin)
v
21 while (t == time (NULL));
str = lielginblgilz lel
a = []
0
void as not.
20
v
22 char n = 0;
}
14 ifstream fin (argv [1]);
7 {
24 cout <<"d =" < [oracle @ localhost ~] $ g seconddisplay.cc
8 int main (int argc, char * argv [])
11
15 string str = “”;
6 int main ()
19 ifstream fin (“a.txt”);
6 char a, b, c, d;
2 using namespace std;
[oracle @ localhost ~] $ vi ascii.cc
[oracle @ localhost ~] $ a.out a.txt
16 while (fin. get (ch)) {
7
23}
13 cout <<"c =["<< c <<"]"<< endl;
9 string str;
23}
return istream object.
[oracle @ localhost ~] $ g file.cc
26}
2 using namespace std;
6 int main ()
16cout < input a char: n = m
4 int main ()
11 cout <<"input a line:";
[oracle @ localhost ~] $ vi getline. cc
cin.ignore (1000, n ;
16 for (;;){
2 using namespace std;
15
6 int main ( )
b = [
6
13
input an integer: 12344567
}
break;
for (int i = 0; i get (char

End of life the object will check the file is closed, not closed the file on shutdown.
C / C code copy the code
ios:: binary = 0×80 / ??/ binary format
home address: Zhengzhou
read by moving the file pointer, you can specify the location in the file read and write.
use the function members get, put, read, write, etc.
display the contents of a text file to copy files
C / C code copy the code
filebuf:: openprot; / / default-compatible sharing
/ / clever use of a text file will not have the character 0
read the characteristics of the results:
Important: the system detects your account there may be risk of theft, please see the risk warning as soon as possible, and immediately change your password. Close
/ / binary file operations example
ios:: in = 0×01, / / ??for reading, the file does not exist, create (ifstream the default open mode)
understand binary file read and write methods
How are you
use eof () function to check whether the read end of the file, use gcount () to obtain the actual number of bytes read
open file
tellp (); / / Returns the current pointer position
fstream f (“d: \ \ 12.dat”, ios:: inios:: outios:: binary); / / open binary file read-write

often read in conjunction with the function gcount (), used to obtain the actual number of bytes read.
if (! f ){…} / /! operator has been overloaded
f.open (“d: \ \ 12.txt”, ios:: out); / / use the same object to operate on multiple files to be used when the open function
Netease blog security alert: The system detected that your current password is less secure, for your account security, we recommend that you change your password immediately amend the timely closure
ifstream / / input file stream
# include void main () {ifstream fin (“d: \ \ Introduction. txt”, ios:: nocreate); if (! fin) {cout <<"File open error! \ n"; return;} char c [80]; while (fin.get (c, 80, 0 ! = NULL) cout < 2011 年 07 月 22 日
seekg (relative position, reference position); / / relative operating
/ / Create a text file and write information / / with output to the screen as the information output to a file # include # include void main () {ofstream f1 (“d: \ \ me.txt”); / / open file for writing, if the file does not exist create it if (! f1) return; / / open file on failure end of the run f1 < C / C Copy the code
failure code:
check the success of open
seekg (absolute position); / / absolute movement, / / ??input stream operation
success:
# include < fstream.h> void main () {ifstream fin (“d: \ \ Introduction. txt”, ios:: nocreate); if (! fin) {cout <<"File open error! \ n"; return;} char c; while ((c = fin.get ())!= EOF) cout < open file method
C / C code copy the code
ios:: beg = 0 / / relative to the file header
“D: \ \ MyFiles \ \ ReadMe.txt”
C file stream:
Note that the path Name of the double-slash to write, such as:
ios:: end = 2 / / relative to the end of the file
if (f ){…} / / for ifstream, ofstream objects available, fstream object is not available.
f.close ();
with the read \ write read and write, but can not be used to insert, extract the operator to operate, or an error occurs.
ios:: ate = 0×04, / / ??file is opened, the file pointer in the final. Can change the location of the pointer, often and in, out
combined read and write text files using the example of
seekp (absolute position); / / absolute movement, / / ??output stream operations
use << ,>> operator
C / C code copy the code to read and write text files
control method
/ / to correctly read the data written to the file, the data is to be among the best There are separate # include void main () {fstream f (“d: \ \ try.txt”, ios:: out); f <<1234 << #39; <<3.14 << < <"How are you"; / / write data f.close (); f.open ("d: \ \ try.txt", ios:: in); int i; double d; char c; char s [ 20]; f>> i>> d>> c; / / read data f.getline (s, 20); cout < ofstream / / output file stream to read and write operations
random access file
reference position:
fstream / / file stream
ios:: noreplace = 0×40, / / ??file exists error, and out often in combination
ios:: out = 0×02, / / for writing, the file does not exist, create, if the file already exists then emptied of the original content (ofstream default open mode)
fstream f;
tellg (); / / Returns the current pointer position
File Open option:
ofstream f (“d: \ \ 12.txt”); / / default to ios:: out of the way to open the file using the member function
close, such as:
Press any key to continue
Open must specify ios:: binary, otherwise it will read and write error
# include void main () {ifstream fin (“d: \ \ Introduction . txt “, ios:: nocreate); if (! fin) {cout <<" File open error! \ n "; return;} char c [80]; while (! fin.eof ()) / / determine the file whether to read the end of {fin.read (c, 80); cout.write (c, fin.gcount ());} fin.close ();}
filebuf:: sh_write; / / write shared
ios:: trunc = 0×10, / / ??before the first file in read length is truncated to 0 (default)
C / C code copy the code to open the file after
run d: \ me.txt, its contents as follows:
ifstream f (“d: \ \ 12.txt”, ios:: nocreate); / / default to ios:: in the open file, file does not exist fails
/ / Use get (char *, int n, char delim = n time reading program two more characters —-
using the Open member function
ios:: app = 0×08, / / ??for writing, the file does not exist, create, if file already exists in the original file contents write new content, position the pointer in the final total
file operations:
file name
# include void main () {ifstream fin (“C: \ \ 1.exe”, ios:: nocreateios:: binary); if (! fin) {cout <<"File open error! \ n"; return ;} ofstream fout ("C: \ \ 2.exe", ios:: binary); char c [1024]; while (! fin.eof ()) {fin.read (c, 1024); fout.write ( c, fin.gcount ());} fin.close (); fout.close (); cout <<"Copy over! \ n";}
constructor is called when the specified file name and open mode
/ / use read (char *, int n) read the file ————————— Option III
seekp (relative position, reference position); / / relative operating
filebuf:: sh_none; / / exclusive, not shared
can only read and write text files, binary files may be used to generate an error.
Name: Lian Oriental
if (f.good ()){…}
ios:: nocreate = 0×20, / / ??file does not exist error, and often in or app joint use
filebuf:: sh_read; / / read the shared

read and write binary files Note
ios:: cur = 1 / / relative to the current position
file protection mode selection:
if (f.fail ()){…}
3.14
requirements:
using destructor
A
1234
close the file
/ / use get () once read a character ————————— —– Option One

Use ifstream encountered a small problem

}
Cout < ifstream ifs (filename);
main ()
the following code:
cout <<"open success" < string temp;
}
char * filename = (char *) malloc (40);
ifstream to open file, requires a c-style string back must be coupled with \ 0
note 40 labeled red, this is below this 40 into 41, solve the problem! From this we can judge interrupted:
strcpy (filename, “/ home / admin / local / apache / logs / access_log”);
{
2011 年 07 月 12 日
getline (ifs, temp);
# include # include
if (ifs.good ()) {
using namespace std;

Use ifstream getline need attention

ios_base:: iostate _State = ios_base:: goodbit;
break;
main code is as follows:
switched http://www.cnblogs.com/chenrj/archive/2009/05/31 / 1 492963.html
while (! fs.eof ())
}
… …
_State= ios_base:: failbit;
if (fs.good ())
std:: vector vecFilelines;
_Chcount = 0;
… …
if (_Ok

C , file I / O operation flow

14
11}
15 std:: cout <<"file open failed!";
14 {
11 / / open file
13};
2 # include
29 rfile.seekg (sizeof (Sprite) * 2, std:: ios:: beg); / / read the Taoist wizard information
22
21 {
39 rsprite.showSprite ();
20 {
38 rfile.read ((char *)

C file I / O (1)

System is a special case, and most of the material discussed in this chapter also apply to other types of devices connected to the stream.
and return reference to the stream.
in the number of bytes transferred.
This encoding method is given below to read and display file encoding shorter cycle:
out. open (“test”, ios:: out);
# include
, the proposed ANSI C standard as an object type with streamsize, these objects shows the input / output operations < br /> outbal.write ((unsigned char *)

C project into a second experiment

{
Double average;
if (linenum == 0)
{
int n = 1;
char next, n1, n2, n3;
exit (1);
cout <<"Input file opening failed.";
fout < fin.open (“d: \ \ file \ \ 5-22 \ \ project.txt “);
if (next ==
change (fin, fout);
}
< strong> # include
}
if (next <|next>
exit (1);
}
}
fin.get (n3);
void change (ifstream

Chapter VIII of the standard IO library

Used to check in one operation or set multiple flags.
“scratchpad” file to the output mode to open and empty. The name “precious” files, then
For some reason, the standard library types do not allow copy or assignment operation. The reason behind the third
in each IO object manages a buffer that stores the program to read and write data. If the following statement:
while (cin>> word)
contents of the buffer is flushed, that is written to the real output device or file:
In addition, the standard library also defines a group of related types, support for wchar_t type. Each class with “w” 382
pieces to clear the stream before the call to clear the state.
8.12:
to use both ways: to achieve some processing on each row, while the other will have to manipulate the process in each row each
cout <<"hi!" < a value in writing before the refresh.
write is the object of the string object. The class also defines a member named str is used to read
8.6:
out to open the file do write, delete the existing data file
s.bad () If you set stream s, badbit value, then the function returns true

ifstream input (it-> c_str ());// open the file;
string stream object to read and write. In addition to the ordinary iostream operations, it also defines a named
not specified in mode, the file will empty the existing data. If you open the file specified trunc
<<"val2:" < outfile.open (“scratchpad”, ofstream:: out);
write function opens the file for input, reads the contents of the file string class
? ostream (output stream) type, to provide output operations.
while (it! = files.end ()) {
1. ifstream, derived from the istream to provide reading files.
member function call open an existing file fstream object with a specific binding. In order to achieve
show form, or vice versa. sstream input and output operations to the arithmetic types can be automatically converted to the corresponding
IO object can not be copied or assignment
and open the code defines a pair of fstream object. infile is read the stream, and outfile
if (outfile) / / ok to use outfile?
8.3. output buffer management
set failbit.
a ostream object can only tied together with an istream object. If you call
os <<"Goodbye!" < achieve IO inheritance is the source of errors. Some errors are recoverable; some mistakes are made
because ifstream inherits istream, so it can ifstream on
cout < default, the stream object associated with the ifstream file will open in mode, this mode allows text
8.4.2. file mode
input.open (it-> c_str ()); / / open the file
object. These two objects are not tied specific file. Using fstream object, you must also
C standard library class to handle input and output:
2. Ofstream, derived from the ostream to provide written documentation of the function.
order, usually according to the final output error to find the program area. If a crash occurs
infile.open (“in “);// open file named” in “in the current directory
s.rdstate () Returns the stream s, current conditions, the return value type strm: : iostate
in.close (); / / close in case it was already open
in the back of a particular output statement, then we can see this location in the program after the error.
/ / ok to use cin, it is in a valid state
book 2010-09-28 11:12:08 Comments 0 read 1 Word Count: C input / output (input / output ) provided by the standard library. Standard library defines a family of types,
the object is the failbit and badbit bit open simultaneously. Arguments:
If the programmer needs to re-file stream to read and write multiple files, you must read another article
pieces. Constructor initializes type using the arrow operator (Section 5.6) the solution of it for reference,
381
prefix, as with the char type versions separate. Thus, wostream, wistream and
8.13:
iostream standard library support for memory input / output, as long as the flow and storage in the program memory
input_istring>> dump>> val1>> dump>> val2;
cin.clear (istream:: failbit); / / reset the stream
control bit, if its value is 1, the operation of the two operands at least one corresponding to the binary bit is 1.
is.badbitis.failbit
? getline function, were required to take istream type and string type, two references
inherited form of type iostream. These types can be used to read and write files or string object.
cout <<"hi!" < 8.4. file input and output
to get it, said the current members of the string object c_str . Open the file by the constructor,
rewrite the above procedures, each word in the document is stored as a
container used here. members get str created before ostringstream object with associated
efficiency, and return to the stream.
international character support does not automatically refresh when the program crashes buffer, which may happen: the program to do
while (cin>> ival,! cin.eof () ) {
default values.
If you ignore the clear call, the loop can only read the first file. To see why, on
which specific error encountered. Table 8.2 lists the standard library functions and defines a set of tags, providing access
standard library defines a number of container classes and a range of generic algorithms, so that programmers can be more concise, abstract and use
iostream type in the same stream on the input and output operations. Standard Library also defines two other
in.open (file.c_str ()); / / open the file we were given
error, then the flow is usually no longer continue to use. If there is a recoverable error, such as the wish to be
then the fstream object is not ready for the IO. When the test object
8.3 lists all the file mode.
The string operator can read the input line of each word. 400
type of vector container, the container object to store each line of one yuan
As istringstream type ifstream and istream classes inherited, so the two known types of string
strings as files name. Fstream object is created, if the call is passed to the
like istream reference parameter to a function. Section 8.2 using the first
asserted state. And then try to open a given file. If the open fails, the state will mark the flow conditions
istream:: iostate old_state = cin.rdstate ();
designers can easily use the standard IO library facilities to read and write custom class objects. Class type usually makes
flow is wistringstream, wostringstream and wstringstream. Standard Library also defines
terminator, terminator corresponding to the fact that the file is another file has nothing to do with the other documents.
read before output.
first calculate each of its operands and returns the right operand as a result of the operation. Therefore,
for open_file function, please explain if you close the program execution functions
s.clear (flag) to the stream s status is set to a specified condition is valid. the type of flag is
string object can be tied up. At this point, you can use iostream input and output operators read this
Exercises Section 8.4.1
each IO header file defines the char and wchar_t types of classes and standard input / output
/ / append mode; adds new data at end of existing file named “file2″
This cycle constantly read cin, until you reach the end of file character or an unrecoverable read error
finish line after a write operation flushed stream:
process (s);
write a function that reads the exercises named file.
8.2:
just call the open function, we must set the file mode, the mode settings can
the Illustration. The top circle represents the base class (or “parent”), the base class and derived class (or “sub
string type of object
copyOut file in both input and output mode on: < br /> ostream print (ostream os);
while (it! = files.end ()) {
strm.str () returns strm type of object stored in the string
/ / construct an ifstream and bind it to the file named ifile
? < windows support files and control devices such as read-write (IO). also defines a number of other types, so that string
while (input>> s) / / do the work on this file
you e already seen a word or a time line of approach for each type of program The first one-way
nounitbuf manipulator will flow back to normal use, flush the buffer by the system management mode.
This requirement has two particularly important implications, as seen in Chapter IX The only support replication of meta-type version of the distinction between
: wchar_t types of standard input object is wcin; standard output is wcout; and standard
following statement is wrong, point out the error and correct it: < br /> reads a word stored in the form of reading the line.
read istringstream object automatically numeric representation of the character data converted to the corresponding count
with this condition is reached before the test cin end of the file or some other error conditions encountered class
C provides for efficient programming using abstract way. standard library is a good example:
out, trunc and app mode can only be used specified ofstream or fstream object associated with the
is equivalent to:
ofstream appfile (“file2″, ofstream:: app);
open mode all of the above combination can also add ate mode of These models will add ate values ??for stream type
differ. In addition, the model can explicitly open the file.
Table 8.3 lists the valid combinations of open modes are inherited
the type of relationship share the same interface. Following Cheng Qiji class derived class property.
Chapter XV of the standard IO library with built-in types defined for the operator and the rules to read and write.
level seems quite terrible. To manage this complexity, the standard library uses inheritance (inheritance)
way to pass the stream object to read and write to the IO object will change its state, so reference must be non-
to define a set of object-oriented (object-oriented) class in the fourth part of the book will be written in more detail
open_file similar program to open the file for output.
outtrunc out the same pattern with
istringstream object to call. Similarly, ostream

Detailed C fstream class (transfer)

put () function writes a character to the stream, and its prototype is ofstream

In C ifstream ofstream can not read Chinese path with a solution

locale:: global (locale (“”));// the global zone is set to the operating system default locale
ifstream instuf (“F: \ \ Chinese path \ \ data.txt”) data sets to identify the Chinese path the
today want to look at pre-treatment data sets, and found that the C ifstream does not recognize the Chinese path, first I do not know this, then I copy the txt to f directly under the root directory, find the can, so look online to find a solution, but I see are written lengthy. I do not love reading, but I just read the file before and after adding such a 2 on the line:
locale:: global (locale (“C “));// restore global zone set
But do not know what the future there will be problems with the. After experiencing a repeat.
and no error was.
2011 年 11 月 03 日