-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbaseASCII.cpp
28 lines (26 loc) · 913 Bytes
/
baseASCII.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
#include <iostream>
#include <vector>
namespace baseASCII
{
void write( const int index, std::ostream & out )
{
if ( index < 0 || index > 255 )
throw "baseASCII: error in making output string";
out << (unsigned char) index;
}
void read( std::istream & ist, std::vector< int > & out )
{
while ( ! ist.eof() )
{
unsigned char buff[1024];
ist.read( (char * ) buff, 1024 );
int imax = ist.gcount();
if ( ( buff[ imax - 1 ] == '\n' ) && ist.eof() )
imax -- ;
for ( int i=0; i<imax; i++ )
{
out.push_back( (int) buff[ i ] );
}
}
}
}