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_Read_Write</id>
		<title>C++/File/File Read Write - История изменений</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_Read_Write"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/File/File_Read_Write&amp;action=history"/>
		<updated>2026-04-07T14:36:20Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/File/File_Read_Write&amp;diff=884&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_Read_Write&amp;diff=884&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_Read_Write&amp;diff=885&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_Read_Write&amp;diff=885&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:06Z</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;==Another example of read() and write() and illustrates the use of gcount( )==&lt;br /&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;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  double doubleNumberArray[4] = {99.75, -34.4, 1776.0, 200.1};&lt;br /&gt;
  int i;&lt;br /&gt;
  ofstream out(&amp;quot;numbers&amp;quot;, 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.write((char *) &amp;amp;doubleNumberArray, sizeof doubleNumberArray);&lt;br /&gt;
  out.close();&lt;br /&gt;
  for(i=0; i&amp;lt;4; i++) // clear array&lt;br /&gt;
    doubleNumberArray[i] = 0.0;&lt;br /&gt;
  ifstream in(&amp;quot;numbers&amp;quot;, ios::in | ios::binary);&lt;br /&gt;
  in.read((char *) &amp;amp;doubleNumberArray, sizeof doubleNumberArray);&lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; in.gcount() &amp;lt;&amp;lt; &amp;quot; bytes read\n&amp;quot;; // see how many bytes have been read&lt;br /&gt;
  for(i=0; i&amp;lt;4; i++) // show values read from file&lt;br /&gt;
     cout &amp;lt;&amp;lt; doubleNumberArray[i] &amp;lt;&amp;lt; &amp;quot; &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;
==Opening Files for Read and Write==&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;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char buffer[255];    &lt;br /&gt;
   ofstream fout(&amp;quot;text.txt&amp;quot;);  &lt;br /&gt;
   fout &amp;lt;&amp;lt; &amp;quot;This line written directly to the file...\n&amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter text for the file: &amp;quot;;&lt;br /&gt;
   cin.ignore(1,&amp;quot;\n&amp;quot;);&lt;br /&gt;
   cin.getline(buffer,255);&lt;br /&gt;
   fout &amp;lt;&amp;lt; buffer &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
   fout.close();         &lt;br /&gt;
   ifstream fin(&amp;quot;text.txt&amp;quot;);    &lt;br /&gt;
   char ch;&lt;br /&gt;
   while (fin.get(ch))&lt;br /&gt;
      cout &amp;lt;&amp;lt; ch;&lt;br /&gt;
   fin.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;
==Reads information from the file and outputs it onto the screen==&lt;br /&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;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
   char data[80];&lt;br /&gt;
   ofstream outfile;&lt;br /&gt;
   outfile.open(&amp;quot;file.dat&amp;quot;);&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 your name: &amp;quot;; &lt;br /&gt;
   cin.getline(data, 80);&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 your id: &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;
   ifstream infile; &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Reading from the file&amp;quot; &amp;lt;&amp;lt; endl; &lt;br /&gt;
   infile.open(&amp;quot;file.dat&amp;quot;); &lt;br /&gt;
   infile &amp;gt;&amp;gt; data; &lt;br /&gt;
   cout &amp;lt;&amp;lt; data &amp;lt;&amp;lt; endl; &lt;br /&gt;
   infile &amp;gt;&amp;gt; data; &lt;br /&gt;
   cout &amp;lt;&amp;lt; data &amp;lt;&amp;lt; endl; &lt;br /&gt;
   infile.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;
==read( ), write( ) and gcount( ):==&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;
   &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  double fnum[4] = {99.75, -34.4, 1776.0, 200.1};&lt;br /&gt;
  int i;&lt;br /&gt;
   &lt;br /&gt;
  ofstream out(&amp;quot;numbers&amp;quot;, 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;
   &lt;br /&gt;
  out.write((char *) &amp;amp;fnum, sizeof fnum);&lt;br /&gt;
   &lt;br /&gt;
  out.close();&lt;br /&gt;
   &lt;br /&gt;
  for(i=0; i&amp;lt;4; i++) // clear array&lt;br /&gt;
    fnum[i] = 0.0;&lt;br /&gt;
   &lt;br /&gt;
  ifstream in(&amp;quot;numbers&amp;quot;, ios::in | ios::binary);&lt;br /&gt;
  in.read((char *) &amp;amp;fnum, sizeof fnum);&lt;br /&gt;
   &lt;br /&gt;
  // see how many bytes have been read&lt;br /&gt;
  cout &amp;lt;&amp;lt; in.gcount() &amp;lt;&amp;lt; &amp;quot; bytes read\n&amp;quot;;&lt;br /&gt;
   &lt;br /&gt;
  for(i=0; i&amp;lt;4; i++) // show values read from file&lt;br /&gt;
  cout &amp;lt;&amp;lt; fnum[i] &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
   &lt;br /&gt;
  in.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;
==Use get() and getline() to read characters.==&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()&lt;br /&gt;
{&lt;br /&gt;
  char ch;&lt;br /&gt;
  char str[256];&lt;br /&gt;
  ofstream fout(&amp;quot;test.dat&amp;quot;);&lt;br /&gt;
  if(!fout) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open file for output.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  fout &amp;lt;&amp;lt; &amp;quot;This is a line of text.\n&amp;quot;;&lt;br /&gt;
  fout &amp;lt;&amp;lt; &amp;quot;This is another line of text.\n&amp;quot;;&lt;br /&gt;
  fout &amp;lt;&amp;lt; &amp;quot;This is the last line of text.\n&amp;quot;;&lt;br /&gt;
  fout.close();&lt;br /&gt;
  if(!fout.good()) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;An error occurred when writing to the file.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  ifstream fin(&amp;quot;test.dat&amp;quot;, ios::in);&lt;br /&gt;
  if(!fin) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Cannot open file for input.\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Use get():\n&amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Here are the first three characters: &amp;quot;;&lt;br /&gt;
  for(int i=0; i &amp;lt; 3; ++i) {&lt;br /&gt;
    fin.get(ch);&lt;br /&gt;
    cout &amp;lt;&amp;lt; ch;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  fin.get(str, 255);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Here is the rest of the first line: &amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; endl;&lt;br /&gt;
  fin.get(ch);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\nNow use getline():\n&amp;quot;;&lt;br /&gt;
  fin.getline(str, 255);&lt;br /&gt;
  cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; endl;&lt;br /&gt;
  fin.getline(str, 255);&lt;br /&gt;
  cout &amp;lt;&amp;lt; str;&lt;br /&gt;
  fin.close();&lt;br /&gt;
  if(!fin.good()) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Error occurred while reading or closing the file.\n&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;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>