-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.cpp
47 lines (43 loc) · 1.03 KB
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "common.h"
//----------------------------------------------------------------
bool operator>>=( std::istream& input, const char* s )
{
const char* p = s;
while( *p )
{
if( input.peek() != *p++ )
{
--p;
for( size_t i = p - s; i > 0; --i )
input.unget();
return false;
}
input.ignore();
}
return true;
}
//----------------------------------------------------------------
std::istream& operator>>( std::istream& input, const char* s )
{
if( !input )
return input;
if( input >>= s )
return input;
std::cerr << "Wrong read! Wait word: \"" << s << '"';
input.setstate( std::ios_base::failbit );
return input;
}
//----------------------------------------------------------------
std::istream& operator>>( std::istream& input, const char c )
{
if( !input )
return input;
if( input.peek() == c )
{
input.ignore();
return input;
}
std::cerr << "Wrong read! Wait char: \"" << c << '"';
input.setstate( std::ios_base::failbit );
return input;
}