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

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/File/ifstream&amp;diff=866&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/ifstream&amp;diff=866&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/ifstream&amp;diff=867&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/ifstream&amp;diff=867&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:03Z</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;==Checking if open function is NULL and ifstream object&amp;quot;s fail==&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;
   ifstream infile;&lt;br /&gt;
   infile.open(&amp;quot;students.dat&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;(infile) = &amp;quot; &amp;lt;&amp;lt; infile &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;(infile.fail()) = &amp;quot; &amp;lt;&amp;lt; infile.fail() &amp;lt;&amp;lt; endl;&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;
==Check status: EOF encountered, Non-Fatal I/O error, Fatal I/O error==&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;
void checkstatus(ifstream &amp;amp;in);&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]);&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 c;&lt;br /&gt;
  while(in.get(c)) {&lt;br /&gt;
    if(in) cout &amp;lt;&amp;lt; c;&lt;br /&gt;
    checkstatus(in);&lt;br /&gt;
  }&lt;br /&gt;
  checkstatus(in);  // check final status&lt;br /&gt;
  in.close();&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
void checkstatus(ifstream &amp;amp;in)&lt;br /&gt;
{&lt;br /&gt;
  ios::iostate i;&lt;br /&gt;
  i = in.rdstate();&lt;br /&gt;
  if(i &amp;amp; ios::eofbit)&lt;br /&gt;
  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;EOF encountered\n&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  else if(i &amp;amp; ios::failbit)&lt;br /&gt;
  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Non-Fatal I/O error\n&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  else if(i &amp;amp; ios::badbit)&lt;br /&gt;
  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Fatal I/O error\n&amp;quot;;&lt;br /&gt;
}&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 with char buffer==&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 | ios::binary);&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 | ios::binary);&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;
==Display a file backwards on the screen: seekg(0, ios::end),tellg() ==&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(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
  if(argc!=2) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;usage: REVERSE &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;
  char ch;&lt;br /&gt;
  long i;&lt;br /&gt;
  // go to end of file (less eof char)&lt;br /&gt;
  in.seekg(0, ios::end);&lt;br /&gt;
  i = (long) in.tellg(); // see how many bytes in file&lt;br /&gt;
  i -= 2;                // backup before eof&lt;br /&gt;
  for( ;i&amp;gt;=0; i--) {&lt;br /&gt;
    in.seekg(i, ios::beg);&lt;br /&gt;
    in.get(ch);&lt;br /&gt;
    cout &amp;lt;&amp;lt; ch;&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;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==displays the contents of a file beginning with the location you specify on the command 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;
#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;
  char ch;&lt;br /&gt;
   &lt;br /&gt;
  if(argc!=3) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: SHOW &amp;lt;filename&amp;gt; &amp;lt;starting location&amp;gt;\n&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&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 file.&amp;quot;;&lt;br /&gt;
    return 1;&lt;br /&gt;
  }&lt;br /&gt;
   &lt;br /&gt;
  in.seekg(atoi(argv[2]), ios::beg);&lt;br /&gt;
   &lt;br /&gt;
  while(in.get(ch))&lt;br /&gt;
    cout &amp;lt;&amp;lt; ch;&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;
==file input with 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;fstream&amp;gt;                &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
using namespace std;  &lt;br /&gt;
  &lt;br /&gt;
int main(){  &lt;br /&gt;
   ifstream infile(&amp;quot;Test.Txt&amp;quot;);   &lt;br /&gt;
  &lt;br /&gt;
   cout &amp;lt;&amp;lt; infile.rdbuf();        &lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;  &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;
==Get Third Type==&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;
     const int max_count = 256;&lt;br /&gt;
     char line[ max_count ];&lt;br /&gt;
     ifstream in( &amp;quot;a.out&amp;quot; );&lt;br /&gt;
     while ( in.get( line, max_count ) ) {                      &lt;br /&gt;
        int count = in.gcount();                                &lt;br /&gt;
        cout &amp;lt;&amp;lt; &amp;quot;num of bytes read:&amp;quot; &amp;lt;&amp;lt; count &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
        if ( count &amp;lt; max_count ) in.ignore();                 &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;
==ifstream.ignore: Ignore up to 10 characters or until first space is found.==&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;
  ifstream in(&amp;quot;test&amp;quot;);&lt;br /&gt;
  if(!in) {&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;
  /* Ignore up to 10 characters or until first space is found. */&lt;br /&gt;
  in.ignore(10, &amp;quot; &amp;quot;);&lt;br /&gt;
  char c;&lt;br /&gt;
  while(in) {&lt;br /&gt;
    in.get(c);&lt;br /&gt;
    if(in) &lt;br /&gt;
       cout &amp;lt;&amp;lt; c;&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;
==ignore( ) reads and discards characters from the input stream.==&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;
// ignore has this prototype: istream &amp;amp;ignore(streamsize num=1, int_type delim=EOF);&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;
  ifstream in(&amp;quot;test&amp;quot;);&lt;br /&gt;
   &lt;br /&gt;
  if(!in) {&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;
  /* Ignore up to 10 characters or until first&lt;br /&gt;
     space is found. */&lt;br /&gt;
  in.ignore(10, &amp;quot; &amp;quot;);&lt;br /&gt;
  char c;&lt;br /&gt;
  while(in) {&lt;br /&gt;
    in.get(c);&lt;br /&gt;
    if(in) cout &amp;lt;&amp;lt; c;&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;
==The ignore( ) Function==&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;
  ifstream in(&amp;quot;test&amp;quot;);&lt;br /&gt;
  if(!in) {&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;
  in.ignore(10, &amp;quot; &amp;quot;);    // Ignore up to 10 characters or until first space is found.&lt;br /&gt;
  char c;&lt;br /&gt;
  while(in) {&lt;br /&gt;
    in.get(c);&lt;br /&gt;
    if(in) cout &amp;lt;&amp;lt; c;&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;
==the use of both checking if the ifstream object used to call the open function is NULL and whether the ifstream object&amp;quot;s fail member function returns true==&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;
   ifstream infile;&lt;br /&gt;
   infile.open(&amp;quot;students.dat&amp;quot;);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;(infile) = &amp;quot; &amp;lt;&amp;lt; infile &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;(infile.fail()) = &amp;quot; &amp;lt;&amp;lt; infile.fail() &amp;lt;&amp;lt; endl;&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;
==Use while loop to read 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;
using namespace std;     &lt;br /&gt;
main(int argc, char *argv[])   &lt;br /&gt;
{   &lt;br /&gt;
  char ch;   &lt;br /&gt;
     &lt;br /&gt;
  if(argc!=2) {   &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Usage: PR &amp;lt;filename&amp;gt;\n&amp;quot;;   &lt;br /&gt;
    return 1;   &lt;br /&gt;
  }   &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 file&amp;quot;;   &lt;br /&gt;
    return 1;   &lt;br /&gt;
  }   &lt;br /&gt;
     &lt;br /&gt;
  while(in) { // in will be 0 when eof is reached   &lt;br /&gt;
    in.get(ch);   &lt;br /&gt;
    cout &amp;lt;&amp;lt; ch;   &lt;br /&gt;
  }   &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;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>