-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase10.cpp
49 lines (44 loc) · 1.42 KB
/
base10.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
48
49
#include <iostream>
#include <vector>
#include "base10.h"
namespace base10
{
namespace
{
const char * s("0123456789");
}
int findSymbol( const char c )
{
for ( int i=0; i<10; i++ )
{
if ( s[i] == c )
return i;
}
return -1;
}
void write ( const int index, std::ostream & out )
{
if ( index < 0 || index > 10 )
throw "base10: error in making output string";
out << s[ index ];
}
void read ( std::istream & ist, std::vector< int > & out )
{
while ( ! ist.eof() )
{
char buff[1024];
ist.read( buff, 1024 );
int imax = ist.gcount();
for ( int i=0; i<imax; i++ )
{
if ( buff[ i ] == '\n' )
return;
int tmp = findSymbol( buff[ i ] );
if ( tmp != -1 )
out.push_back( tmp );
else
throw "base10: incorrect symbol found";
}
}
}
}