C++ Tutorial/File Stream/istream

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Define your own istream type

#include<iostream.h>
#include<string.h>
istream & skipchar(istream &stream)
{
  int i;
  char c;
  for(i=0;i<5;i++) stream>>c;
  return stream;
}
main()
{
  char str[80];
  cout<<"Enter some characters:";
  cin>>skipchar>>str;
  cout<<str<<"\n";
  return 0;
}
Enter some characters:q
w
e
r
t
r
r

Oct Input stream

#include <iostream.h>
#include <iomanip.h>
istream& OctInput(istream& is);
main(void)
{
  int n;
  cin >> OctInput >> n;
  cout << "n:" << n << endl;
  cout << "hex:" <<hex<< n << endl;
  return 0;
}
istream& OctInput(istream& is)
{
  cout <<"input:";
  cin >> oct;
  return is;
}
input:12
n:10
hex:a