⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iosbase.htm

📁 这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明
💻 HTM
📖 第 1 页 / 共 2 页
字号:
</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 &lt;iostream&gt;
    6   #include &lt;sys/stat.h&gt;
    7   #include &lt;dirent.h&gt;       // Requires POSIX compatibility
    8   #include &lt;string.h&gt;
    9   #include &lt;dir.h&gt;
   10   #include &lt;time.h&gt;
   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-&gt;d_name,&Buffer) == 0){
   28   		     DirectorySize = DirectorySize + Buffer.st_size;
   29   		 }
   30   		 else{
   31   		      cerr &lt;&lt; "could not stat " &lt;&lt; Entry-&gt;d_name &lt;&lt; endl;
   32   		 }
   33   		 Entry = readdir(Directory);
   34   	   }
   35   	   rewinddir(Directory);
   36   	   cout &lt;&lt; "\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-&gt;d_name,&Buffer);
   45   	     cout &lt;&lt; Entry-&gt;d_name &lt;&lt; "\t";
   46   	     cout.width(12);
   47   	     cout.setf(ios::right);
   48   	     cout.fill(' ');
   49   	     cout.setf(ios::dec);
   50   	     cout &lt;&lt; Buffer.st_size &lt;&lt; "\t ";
   51   	     cout.width(12);
   52   	     cout.setf(ios::right);
   53   	     cout.fill(' ');
   54   	     cout.setf(ios::hex);
   55   	     cout &lt;&lt; Buffer.st_size &lt;&lt; "\t";
   56   	     cout.width(9);
   57   	     cout.setf(ios::right | ios::showpoint);
   58   	     cout.fill(' ');
   59   	     cout &lt;&lt; (Buffer.st_size/DirectorySize*100) &lt;&lt; '%' &lt;&lt; "\t";
   60   	     cout.width(9);
   61   	     cout.setf(ios::right);
   62   	     cout.setf(ios::scientific);
   63   	     cout.fill(' ');
   64   	     cout &lt;&lt; (Buffer.st_size/DirectorySize * 100) &lt;&lt; '%' &lt;&lt; "\t";
   65   	     cout.width(12);
   66   	     cout.setf(ios::left);
   67   	     cout &lt;&lt; ctime(&Buffer.st_atime) &lt;&lt; endl;
   68   	     Entry = readdir(Directory);
   69   	   }
   70   	   cout.precision(0);
   71   	   cout.setf(ios::oct | ios::fixed);
   72   	   cout &lt;&lt; "Directory Size: " &lt;&lt; DirectorySize &lt;&lt; endl;
   73   	}
   74   	else{
   75   	      cerr &lt;&lt; "could not open " &lt;&lt; Argv[1] &lt;&lt; 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 + -