User Tools

Site Tools


c_-_c_files:file_seek

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
c_-_c_files:file_seek [2017/10/12 14:56] – created peterc_-_c_files:file_seek [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 31: Line 31:
            
   return 0;      return 0;   
 +}
 +</code>
 +
 +
 +
 +===== Seek and Skip =====
 +
 +<code cpp>
 +#include <fstream>
 +#include <iostream>
 + 
 +using namespace std;
 + 
 +int main()
 +{
 +  ifstream in("datafile");
 +  in.unsetf(ios::skipws);                     
 +  char ch;
 +
 +  while (in >> ch) 
 +  {
 +    cout << ch;                                 
 +  }
 + 
 +  cout << '\n';
 +
 +  in.clear();
 +  in.seekg(ios::beg);                         
 +  in.setf(ios::skipws);                       
 +
 +  while (in >> ch)
 +  {
 +    cout << ch;                            
 +  }
 +
 +  cout << '\n';
 +
 +  return 0;
 } }
 </code> </code>
  
c_-_c_files/file_seek.1507820207.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki