A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FFile%2FFile_Utility</id>
		<title>C++/File/File Utility - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FFile%2FFile_Utility"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/File/File_Utility&amp;action=history"/>
		<updated>2026-04-09T22:05:34Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/File/File_Utility&amp;diff=878&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/File/File_Utility&amp;diff=878&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/File/File_Utility&amp;diff=879&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/File/File_Utility&amp;diff=879&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:05Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Concatenate files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using std::cerr;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::getline;&lt;br /&gt;
using std::ifstream;&lt;br /&gt;
using std::string;&lt;br /&gt;
int main(int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
  int fail_count = 0;&lt;br /&gt;
  for (int i = 1; i &amp;lt; argc; ++i) {&lt;br /&gt;
    ifstream in(argv[i]);&lt;br /&gt;
    if (in) {&lt;br /&gt;
      string s;&lt;br /&gt;
      while (getline(in, s))&lt;br /&gt;
        cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; endl;&lt;br /&gt;
    } else {&lt;br /&gt;
      cerr &amp;lt;&amp;lt; &amp;quot;cannot open file &amp;quot; &amp;lt;&amp;lt; argv[i] &amp;lt;&amp;lt; endl;&lt;br /&gt;
      ++fail_count;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return fail_count;&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Copy a file and display number of chars copied.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: CPY &amp;lt;input&amp;gt; &amp;lt;output&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream fin(argv[1], ios::in | ios::binary); // open input file&lt;br /&gt;
  ofstream fout(argv[2], ios::out | ios::binary); // create output file&lt;br /&gt;
  if(!fin) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  if(!fout) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open output file\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char ch;&lt;br /&gt;
  unsigned count=0;&lt;br /&gt;
  while(!fin.eof()) {&lt;br /&gt;
    fin.get(ch);&lt;br /&gt;
    if(!fin.eof()) {&lt;br /&gt;
      fout.put(ch);&lt;br /&gt;
      count++;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Number of bytes copied: &amp;quot; &amp;lt;&amp;lt; count &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  fin.close();&lt;br /&gt;
  fout.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Copy a file and reverse case of letters.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  char ch;&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: COPYREV &amp;lt;source&amp;gt; &amp;lt;target&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[1]);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ofstream out(argv[2]);&lt;br /&gt;
  if(!out) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open output file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    ch = in.get();&lt;br /&gt;
    if(!in.eof()) {&lt;br /&gt;
      if(islower(ch)) ch = toupper(ch);&lt;br /&gt;
      else ch = tolower(ch);&lt;br /&gt;
      out.put(ch);&lt;br /&gt;
    }&lt;br /&gt;
  };&lt;br /&gt;
  in.close();&lt;br /&gt;
  out.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Copy a file and reverse case of letters with error checking.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  char ch;&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: COPYREV &amp;lt;source&amp;gt; &amp;lt;target&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[1]);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ofstream out(argv[2]);&lt;br /&gt;
  if(!out) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open output file&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    ch = in.get();&lt;br /&gt;
    if(!in.good() &amp;amp;&amp;amp; !in.eof()) &lt;br /&gt;
      return 1;&lt;br /&gt;
    if(!in.eof()) {&lt;br /&gt;
      if(islower(ch)) &lt;br /&gt;
         ch = toupper(ch);&lt;br /&gt;
      else &lt;br /&gt;
         ch = tolower(ch);&lt;br /&gt;
      out.put(ch);&lt;br /&gt;
      if(!out.good()) &lt;br /&gt;
         return 1;&lt;br /&gt;
    }&lt;br /&gt;
  };&lt;br /&gt;
  in.close();&lt;br /&gt;
  out.close();&lt;br /&gt;
  if(!in.good() &amp;amp;&amp;amp; !out.good()) &lt;br /&gt;
     return 1;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Copy and convert tabs to spaces.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: CPY &amp;lt;in&amp;gt; &amp;lt;out&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[1]);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ofstream out(argv[2]);&lt;br /&gt;
  if(!out) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open output file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char ch;&lt;br /&gt;
  int i = 8;&lt;br /&gt;
    &lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    in.get(ch); &lt;br /&gt;
    if(ch==&amp;quot;\t&amp;quot;) &lt;br /&gt;
       for( ; i&amp;gt;0; i--) &lt;br /&gt;
          out.put(&amp;quot; &amp;quot;);&lt;br /&gt;
    else out.put(ch);&lt;br /&gt;
    if(i == -1 || ch==&amp;quot;\n&amp;quot;) i = 8;&lt;br /&gt;
    i--;&lt;br /&gt;
  }&lt;br /&gt;
  in.close();&lt;br /&gt;
  out.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Copy a text file and display number of chars copied.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: Copy &amp;lt;input&amp;gt; &amp;lt;output&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream fin(argv[1]); // open input file&lt;br /&gt;
  ofstream fout(argv[2]);  // create output file&lt;br /&gt;
  if(!fin) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  if(!fout) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open output file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char ch;&lt;br /&gt;
  unsigned count=0;&lt;br /&gt;
  fin.unsetf(ios::skipws);  // do not skip spaces&lt;br /&gt;
  while(!fin.eof()) {&lt;br /&gt;
    fin &amp;gt;&amp;gt; ch;&lt;br /&gt;
    if(!fin.eof()) {&lt;br /&gt;
      fout &amp;lt;&amp;lt; ch;&lt;br /&gt;
      count++;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Number of bytes copied: &amp;quot; &amp;lt;&amp;lt; count &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  fin.close();&lt;br /&gt;
  fout.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Copy files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char **argv)&lt;br /&gt;
 {&lt;br /&gt;
   char buffer[1];&lt;br /&gt;
   &lt;br /&gt;
   ifstream input(argv[1], ios::in);&lt;br /&gt;
   if (input.fail())&lt;br /&gt;
    {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Error opening the file &amp;quot; &amp;lt;&amp;lt; argv[1];&lt;br /&gt;
      exit(1);&lt;br /&gt;
    }&lt;br /&gt;
   ofstream output(argv[2], ios::out);&lt;br /&gt;
   if (output.fail())&lt;br /&gt;
    {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Error opening the file &amp;quot; &amp;lt;&amp;lt; argv[2];&lt;br /&gt;
      exit(1);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
   do {&lt;br /&gt;
     input.read(buffer, sizeof(buffer));&lt;br /&gt;
     if (input.good())&lt;br /&gt;
       output.write(buffer, sizeof(buffer));&lt;br /&gt;
   } while (! input.eof());&lt;br /&gt;
   input.close();&lt;br /&gt;
   output.close(); &lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Count letters.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int alpha[26];&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  char ch;&lt;br /&gt;
  if(argc!=2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: COUNT &amp;lt;source&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[1]);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  // init alpha[]&lt;br /&gt;
  int i;&lt;br /&gt;
  for(i = 0; i &amp;lt;26; i++) alpha[ i ] = 0;&lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    ch = in.get();&lt;br /&gt;
    if(isalpha(ch)) { &lt;br /&gt;
      ch = toupper(ch); &lt;br /&gt;
      alpha[ch-&amp;quot;A&amp;quot;]++;&lt;br /&gt;
    }&lt;br /&gt;
  };&lt;br /&gt;
  for(i = 0; i &amp;lt;26; i++) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; (char) (&amp;quot;A&amp;quot;+ i) &amp;lt;&amp;lt; &amp;quot;: &amp;quot; &amp;lt;&amp;lt; alpha[ i ] &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  in.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create a file comparision utility.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
#include &amp;lt;fstream&amp;gt;  &lt;br /&gt;
using namespace std;  &lt;br /&gt;
  &lt;br /&gt;
int main(int argc, char *argv[])  &lt;br /&gt;
{  &lt;br /&gt;
  register int i;  &lt;br /&gt;
  int numread;  &lt;br /&gt;
  &lt;br /&gt;
  unsigned char buffer1[1024], buffer2[1024];  &lt;br /&gt;
  &lt;br /&gt;
  if(argc!=3) {  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: compfiles &amp;lt;file1&amp;gt; &amp;lt;file2&amp;gt;\n&amp;quot;;  &lt;br /&gt;
    return 1;  &lt;br /&gt;
  }  &lt;br /&gt;
  &lt;br /&gt;
  ifstream f1(argv[1], ios::in | ios::binary);  &lt;br /&gt;
  if(!f1) {  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open first file.\n&amp;quot;;  &lt;br /&gt;
    return 1;  &lt;br /&gt;
  }  &lt;br /&gt;
  ifstream f2(argv[2], ios::in | ios::binary);  &lt;br /&gt;
  if(!f2) {  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open second file.\n&amp;quot;;  &lt;br /&gt;
    return 1;  &lt;br /&gt;
   }  &lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Comparing files...\n&amp;quot;;  &lt;br /&gt;
  &lt;br /&gt;
  do {  &lt;br /&gt;
    f1.read((char *) buffer1, sizeof buffer1);  &lt;br /&gt;
    f2.read((char *) buffer2, sizeof buffer2);  &lt;br /&gt;
 &lt;br /&gt;
    if(f1.gcount() != f2.gcount()) { &lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Files are of differing sizes.\n&amp;quot;; &lt;br /&gt;
      f1.close();  &lt;br /&gt;
      f2.close();  &lt;br /&gt;
      return 0; &lt;br /&gt;
    } &lt;br /&gt;
    &lt;br /&gt;
    for(i = 0; i &amp;lt;f1.gcount(); i++)  // compare contents of buffers  &lt;br /&gt;
      if(buffer1[i] != buffer2[i]) {  &lt;br /&gt;
        cout &amp;lt;&amp;lt; &amp;quot;Files differ.\n&amp;quot;;  &lt;br /&gt;
        f1.close();  &lt;br /&gt;
        f2.close();  &lt;br /&gt;
        return 0;  &lt;br /&gt;
      }  &lt;br /&gt;
  &lt;br /&gt;
  } while(!f1.eof() &amp;amp;&amp;amp; !f2.eof());  &lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Files are the same.\n&amp;quot;;  &lt;br /&gt;
  &lt;br /&gt;
  f1.close();  &lt;br /&gt;
  f2.close();  &lt;br /&gt;
  &lt;br /&gt;
  return 0;  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Display contents of specified file in both ASCII and in hex.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc != 2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: Display &amp;lt;filename&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[ 1 ], ios::in | ios::binary);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  register int i, j;&lt;br /&gt;
  int count = 0;&lt;br /&gt;
  char c[16];&lt;br /&gt;
  cout.setf(ios::uppercase);&lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    for(i = 0; i &amp;lt; 16 &amp;amp;&amp;amp; !in.eof(); i++) {&lt;br /&gt;
      in.get(c[i]);&lt;br /&gt;
    }&lt;br /&gt;
    if(i &amp;lt;16) &lt;br /&gt;
       i--;                                 // get rid of eof&lt;br /&gt;
    for(j = 0; j &amp;lt; i; j++)&lt;br /&gt;
      cout &amp;lt;&amp;lt; setw(3) &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; (int) c[j];&lt;br /&gt;
    for(; j &amp;lt; 16; j++) &lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;   &amp;quot;;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;\t&amp;quot;;&lt;br /&gt;
    for(j = 0; j &amp;lt; i; j++)&lt;br /&gt;
      if(isprint(c[ j ])) &lt;br /&gt;
         cout &amp;lt;&amp;lt; c[ j ];&lt;br /&gt;
      else &lt;br /&gt;
         cout &amp;lt;&amp;lt; &amp;quot;.&amp;quot;;&lt;br /&gt;
    cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
    count++;&lt;br /&gt;
    if(count == 16) {&lt;br /&gt;
      count = 0;&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Press ENTER to continue: &amp;quot;;&lt;br /&gt;
      cin.get();&lt;br /&gt;
      cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  in.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Read and display a text file line by line.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc != 2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: Display &amp;lt;filename&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[ 1 ]);                 // input&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char str[ 255 ];&lt;br /&gt;
  while(in) {&lt;br /&gt;
    in.getline(str, 255);                // delim defaults to &amp;quot;\n&amp;quot;&lt;br /&gt;
    if(in) &lt;br /&gt;
       cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; endl;&lt;br /&gt;
  }&lt;br /&gt;
  in.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Search file.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: SEARCH &amp;lt;file&amp;gt; &amp;lt;word&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[1]);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char str[255];&lt;br /&gt;
  int count=0;&lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    in &amp;gt;&amp;gt; str;&lt;br /&gt;
    if(!strcmp(str, argv[2])) count++;    &lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; argv[2] &amp;lt;&amp;lt; &amp;quot; found &amp;quot; &amp;lt;&amp;lt; count;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot; number of times.\n&amp;quot;;&lt;br /&gt;
  in.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Swap characters in a file.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;usage: SWAP &amp;lt;filename&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  // open file for input/output&lt;br /&gt;
  fstream io(argv[1], ios::in | ios::out | ios::binary);&lt;br /&gt;
  if(!io) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char ch1, ch2;&lt;br /&gt;
  long i;&lt;br /&gt;
  for(i = 0 ; !io.eof(); i+=2) {&lt;br /&gt;
    io.seekg(i, ios::beg);&lt;br /&gt;
    io.get(ch1);&lt;br /&gt;
    if(io.eof()) continue;&lt;br /&gt;
    io.get(ch2);&lt;br /&gt;
    if(io.eof()) continue;&lt;br /&gt;
    io.seekg(i, ios::beg);&lt;br /&gt;
    io.put(ch2);&lt;br /&gt;
    io.put(ch1);&lt;br /&gt;
  }&lt;br /&gt;
  io.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Swap characters in a file with error checking.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;usage: SWAP &amp;lt;filename&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  // open file for input/output&lt;br /&gt;
  fstream io(argv[1], ios::in | ios::out | ios::binary);&lt;br /&gt;
  if(!io) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  char ch1, ch2;&lt;br /&gt;
  long i;&lt;br /&gt;
  for(i = 0 ;!io.eof(); i+=2) {&lt;br /&gt;
    io.seekg(i, ios::beg);&lt;br /&gt;
    if(!io.good()) &lt;br /&gt;
       return 1;&lt;br /&gt;
    io.get(ch1);&lt;br /&gt;
    if(io.eof()) &lt;br /&gt;
       continue;&lt;br /&gt;
    io.get(ch2);&lt;br /&gt;
    if(!io.good()) &lt;br /&gt;
       return 1;&lt;br /&gt;
    if(io.eof()) &lt;br /&gt;
       continue;&lt;br /&gt;
    io.seekg(i, ios::beg);&lt;br /&gt;
    if(!io.good()) &lt;br /&gt;
       return 1;&lt;br /&gt;
    io.put(ch2);&lt;br /&gt;
    if(!io.good()) &lt;br /&gt;
       return 1;&lt;br /&gt;
    io.put(ch1);&lt;br /&gt;
    if(!io.good()) &lt;br /&gt;
       return 1;&lt;br /&gt;
  }&lt;br /&gt;
  io.close();&lt;br /&gt;
  if(!io.good()) return 1;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Word count for input file: file read with ifstream==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: COUNT &amp;lt;input&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream in(argv[1]);&lt;br /&gt;
  if(!in) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open input file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  int count=0;&lt;br /&gt;
  char ch;&lt;br /&gt;
  in &amp;gt;&amp;gt; ch; // find first non-space char&lt;br /&gt;
  // after first non-space found, do not skip spaces&lt;br /&gt;
  in.unsetf(ios::skipws);&lt;br /&gt;
  while(!in.eof()) {&lt;br /&gt;
    in &amp;gt;&amp;gt; ch;&lt;br /&gt;
    if(isspace(ch)) {&lt;br /&gt;
      count++;&lt;br /&gt;
      while(isspace(ch) &amp;amp;&amp;amp; !in.eof()) &lt;br /&gt;
         in &amp;gt;&amp;gt; ch; // find next word&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Word count: &amp;quot; &amp;lt;&amp;lt; count &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  in.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>