📄 iosbase.htm
字号:
</p>
<hr>
<pre>
<a name="register">Method register_callback()</a>
Access Public
Classification Modifier
Syntax void register_callback(event_call_back Fn,
int Ndx);
Parameters Fn is a pointer to a function and will be
called with the argument Ndx. Ndx is position
in the array that represents a format flag.
Return None
</pre>
<h3>Description</h3>
<p>
The register_callback() method is used to register functions and indexes that can be used when a call back event occurs. The functions are called in LIFO(last in first out) manner. The ios_base class supports three call back events.
</p>
<h3>Event Call Backs</h3>
<pre>
<b>Event</b> <b>Occurs</b>
________________________________________________________________
imbue_event during a call to imbue()
erase_event during a call to ~ios_base() or
copyfmt()
copyfmt_event during a call to copyfmt()
________________________________________________________________
</pre>
<pre>
<a name="setf1">Method setf()</a>
Access Public
Classification Modifier
Syntax fmtflags setf(fmtflags FlagArg);
Parameters FlagArg contains the new value for the
format flags
Return The previous value of the ios_base
format flags.
</pre>
<h3>Description</h3>
<p>
This setf() method changes the value of the ios_base format flags to the value in FlagArg. It returns the previous value for the format flags.
</p>
<hr>
<pre>
<a name="setf2">Method setf()</a>
Access Public
Classification Modifier
Syntax fmtflags setf(fmtflags FlagArg,
fmtflags Mask);
Parameters FlagArg contains the new value for the
format flags, Mask contains the value
to be cleared in the format flags.
Return The previous value of the ios_base
format flags.
</pre>
<h3>Description</h3>
<p>
This setf() method clears the value of the Mask value in the corresponding format flags. It sets the value of the ios_base format flags to the value of (FlagArg & Mask). It returns the previous value for the format flags.
</p>
<hr>
<pre>
<a name="sync">Method sync_width_stdio()</a>
Access Public
Classification Modifier
Syntax static bool sync_with_stdio(bool Sync = true);
Parameters Sync contains the new value for the
input/output synchronization flag.The
default value is true.
Return The previous synchronization value
</pre>
<h3>Description</h3>
<p>
The sync_with_stdio() method sets the input/output synchronization flag. If synchronization is true then the iostreams I/O will be synchronized with the standard C library input/output. If it is false there is no guarantee that the I/O calls will be synchronized. However performance is usually improved with synchronization is false.
</p>
<hr>
<pre>
<a name="unsetf">Method unsetf()</a>
Access Public
Classification Modifier
Syntax void unsetf(fmtflags Mask);
Parameters Mask the value to be cleared in the format
flags
Return None
</pre>
<h3>Description</h3>
<p>
The unsetf() method clears the bits in the format flags that correspond to Mask.
</p>
<hr>
<pre>
<a name="width1">Method width()</a>
Access Public
Classification Accessor
Syntax streamsize width(void);
Parameters None
Return The current settings of the stream width.
</pre>
<h3>Description</h3>
<p>
This width() method returns the current width setting for the stream.
</p>
<hr>
<pre>
<a name="width2">Method width()</a>
Access Public
Classification Modifier
Syntax streamsize width(streamsize Wd);
Parameters Wd the size that the new field width will
be set to.
Return The previous width of the stream.
</pre>
<h3>Description</h3>
<p>
This width method sets the new field width to Wd. It returns the previous field width.
</p>
<hr>
<pre>
<a name="xalloc">Method xalloc()</a>
Access Public
Classification Modifier
Syntax static int xalloc();
Parameters None
Return An index into array of values that can be
used for user defined format flags.
</pre>
<h3>Description</h3>
<p>
The xalloc() method returns a value that can be used for user defined format flags. It is used in conjunction with the iword() and pword() methods.
</p>
<hr>
<p>
<a name="diagram"><h2>The Class Relationship Diagram of ios_base</h2></a>
<img src="iosbase.gif">
</p>
<hr>
<a name="example"></a>
<img src="lego.gif">
<pre>
<code>
2 // This program demonstrates the use of the format flags, and
3 // formatting capabilities of the ios_base component
4
5 #include <iostream>
6 #include <sys/stat.h>
7 #include <dirent.h> // Requires POSIX compatibility
8 #include <string.h>
9 #include <dir.h>
10 #include <time.h>
11
12 using namespace std;
13
14 int main(int Argc,char *Argv[])
15 {
16 if(Argc == 2){
17 DIR *Directory;
18 Directory = opendir(Argv[1]);
19 chdir(Argv[1]);
20 if(!Directory == NULL){
21 float DirectorySize = 0;
22 struct dirent *Entry;
23 struct stat Buffer;
24 Entry = readdir(Directory);
25 while(Entry != NULL)
26 {
27 if (stat(Entry->d_name,&Buffer) == 0){
28 DirectorySize = DirectorySize + Buffer.st_size;
29 }
30 else{
31 cerr << "could not stat " << Entry->d_name << endl;
32 }
33 Entry = readdir(Directory);
34 }
35 rewinddir(Directory);
36 cout << "\f";
37 cout.precision(4);
38 Entry = readdir(Directory);
39 while(Entry != NULL)
40 {
41 cout.setf(ios::left | ios::fixed);
42 cout.fill('*');
43 cout.width(20);
44 stat(Entry->d_name,&Buffer);
45 cout << Entry->d_name << "\t";
46 cout.width(12);
47 cout.setf(ios::right);
48 cout.fill(' ');
49 cout.setf(ios::dec);
50 cout << Buffer.st_size << "\t ";
51 cout.width(12);
52 cout.setf(ios::right);
53 cout.fill(' ');
54 cout.setf(ios::hex);
55 cout << Buffer.st_size << "\t";
56 cout.width(9);
57 cout.setf(ios::right | ios::showpoint);
58 cout.fill(' ');
59 cout << (Buffer.st_size/DirectorySize*100) << '%' << "\t";
60 cout.width(9);
61 cout.setf(ios::right);
62 cout.setf(ios::scientific);
63 cout.fill(' ');
64 cout << (Buffer.st_size/DirectorySize * 100) << '%' << "\t";
65 cout.width(12);
66 cout.setf(ios::left);
67 cout << ctime(&Buffer.st_atime) << endl;
68 Entry = readdir(Directory);
69 }
70 cout.precision(0);
71 cout.setf(ios::oct | ios::fixed);
72 cout << "Directory Size: " << DirectorySize << endl;
73 }
74 else{
75 cerr << "could not open " << Argv[1] << endl;
76 }
77 closedir(Directory);
78 return(1);
79 }
80 return(0);
81
82 }
</code>
</pre>
<hr>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -