C++ Tutorial/File Stream/istream — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 13:31, 25 мая 2010

Define your own istream type

<source lang="cpp">#include<iostream.h>

  1. 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;

}</source>

Enter some characters:q
w
e
r
t
r
r

Oct Input stream

<source lang="cpp">#include <iostream.h>

  1. 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;

}</source>

input:12
n:10
hex:a