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

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/File/fstream&amp;diff=892&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/File/fstream&amp;diff=892&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://www.cppe.ru/index.php?title=C%2B%2B/File/fstream&amp;diff=893&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/File/fstream&amp;diff=893&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:07Z</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;==Demonstrate File random access.==&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;cstdlib&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;
  if(argc != 3) { &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: CHANGE &amp;lt;filename&amp;gt; &amp;lt;byte&amp;gt;\n&amp;quot;; &lt;br /&gt;
    return 1; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  fstream out(argv[1], ios::in | ios::out | ios::binary); &lt;br /&gt;
  if(!out) { &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;
 &lt;br /&gt;
  out.seekp(atoi(argv[2]), ios::beg); &lt;br /&gt;
 &lt;br /&gt;
  out.put(&amp;quot;X&amp;quot;); &lt;br /&gt;
  out.close(); &lt;br /&gt;
 &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;
==File Stream Objects as Function Arguments==&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;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
bool writeFile (ofstream&amp;amp;, char*);&lt;br /&gt;
bool readFile (ifstream&amp;amp;, char*);&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
   string data;&lt;br /&gt;
   bool status;&lt;br /&gt;
   ofstream outfile;&lt;br /&gt;
   status = writeFile(outfile, &amp;quot;students.dat&amp;quot;);&lt;br /&gt;
   if (!status)&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;File could not be opened for writing\n&amp;quot;;&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Program terminating\n&amp;quot;;&lt;br /&gt;
      return 0;&lt;br /&gt;
   }&lt;br /&gt;
   else&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Writing to the file&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Enter class name: &amp;quot;; &lt;br /&gt;
      getline(cin, data); &lt;br /&gt;
      outfile &amp;lt;&amp;lt; data&amp;lt;&amp;lt; endl;&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Enter number of students: &amp;quot;; &lt;br /&gt;
      cin &amp;gt;&amp;gt; data;&lt;br /&gt;
      cin.ignore();&lt;br /&gt;
      outfile &amp;lt;&amp;lt; data&amp;lt;&amp;lt; endl;&lt;br /&gt;
      outfile.close();&lt;br /&gt;
   }&lt;br /&gt;
   ifstream infile;&lt;br /&gt;
   status = readFile(infile, &amp;quot;students.dat&amp;quot;);&lt;br /&gt;
   if (!status)&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;File could not be opened for reading\n&amp;quot;;&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Program terminating\n&amp;quot;;&lt;br /&gt;
      return 0;&lt;br /&gt;
   }&lt;br /&gt;
   else&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Reading from the file&amp;quot; &amp;lt;&amp;lt; endl; &lt;br /&gt;
      getline(infile, data);&lt;br /&gt;
      while(!infile.fail())&lt;br /&gt;
      {&lt;br /&gt;
         cout &amp;lt;&amp;lt; data &amp;lt;&amp;lt; endl; &lt;br /&gt;
         getline(infile, data);&lt;br /&gt;
      }&lt;br /&gt;
      infile.close();&lt;br /&gt;
   }&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
bool writeFile (ofstream&amp;amp; file, char* strFile)&lt;br /&gt;
{&lt;br /&gt;
   file.open(strFile);&lt;br /&gt;
   if (file.fail())&lt;br /&gt;
         return false;&lt;br /&gt;
   else&lt;br /&gt;
         return true;&lt;br /&gt;
}&lt;br /&gt;
bool readFile (ifstream&amp;amp; ifile, char* strFile)&lt;br /&gt;
{&lt;br /&gt;
   ifile.open(strFile);&lt;br /&gt;
   if (ifile.fail())&lt;br /&gt;
         return false;&lt;br /&gt;
   else&lt;br /&gt;
         return true;&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;
==fstream seekp: Seek file pointer position==&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;cstdlib&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 != 4) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: CHANGE &amp;lt;filename&amp;gt; &amp;lt;character&amp;gt; &amp;lt;char&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  fstream out(argv[1], ios::in | ios::out | ios::binary);&lt;br /&gt;
  if(!out) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open file.&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  out.seekp(atoi(argv[ 2 ]), ios::beg);&lt;br /&gt;
  out.put(*argv[ 3 ]);&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;
==Reverse file content==&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;cstdlib&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: Reverse &amp;lt;filename&amp;gt; &amp;lt;num&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  fstream inout(argv[1], ios::in | ios::out | ios::binary);&lt;br /&gt;
  if(!inout) {&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;
  long e, i, j;&lt;br /&gt;
  char c1, c2;&lt;br /&gt;
  e = atol(argv[2]);&lt;br /&gt;
  for(i = 0, j = e; i &amp;lt; j; i++, j--) {&lt;br /&gt;
    inout.seekg(i, ios::beg);&lt;br /&gt;
    inout.get(c1);&lt;br /&gt;
    inout.seekg(j, ios::beg);&lt;br /&gt;
    inout.get(c2);&lt;br /&gt;
    inout.seekp(i, ios::beg);&lt;br /&gt;
    inout.put(c2);&lt;br /&gt;
    inout.seekp(j, ios::beg);&lt;br /&gt;
    inout.put(c1);&lt;br /&gt;
  }&lt;br /&gt;
  inout.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;
==Reverses the first N characters within 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;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdlib&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  long n, i, j;&lt;br /&gt;
  char ch1, ch2;&lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: Reverse &amp;lt;filename&amp;gt; &amp;lt;num&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  fstream finout(argv[1], ios::in | ios::out | ios::binary);&lt;br /&gt;
  if(!finout) {&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;
  n = atol(argv[2]) - 1;&lt;br /&gt;
  for(i=0, j=n; i &amp;lt; j; ++i, --j) {&lt;br /&gt;
    finout.seekg(i, ios::beg);&lt;br /&gt;
    finout.get(ch1);&lt;br /&gt;
 &lt;br /&gt;
    finout.seekp(j, ios::beg);&lt;br /&gt;
    finout.put(ch1);&lt;br /&gt;
    if(!finout.good()) {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Error reading or writing characters.&amp;quot;;&lt;br /&gt;
      finout.clear();&lt;br /&gt;
      break;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  finout.close();&lt;br /&gt;
  if(!finout.good()) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;A file error occurred.&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&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;
==To read or write to a file, you include &amp;lt;fstream&amp;gt;==&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;fstream&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  using namespace std;&lt;br /&gt;
  int intValue;&lt;br /&gt;
  float realValue;&lt;br /&gt;
  ifstream inData;&lt;br /&gt;
  ofstream outData;&lt;br /&gt;
  inData.open(&amp;quot;input.dat&amp;quot;);&lt;br /&gt;
  outData.open(&amp;quot;output.dat&amp;quot;);&lt;br /&gt;
  inData  &amp;gt;&amp;gt; intValue;&lt;br /&gt;
  inData  &amp;gt;&amp;gt; realValue;&lt;br /&gt;
  outData &amp;lt;&amp;lt; &amp;quot;The input values are &amp;quot;&lt;br /&gt;
          &amp;lt;&amp;lt; intValue  &amp;lt;&amp;lt; &amp;quot; and &amp;quot;&lt;br /&gt;
          &amp;lt;&amp;lt; realValue   &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0 ;&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>