Stream Input: operator >> ()

unsigned_int<> provides a templated overload of:

std::basic_ostream<..> &operator >> (
    std::basic_ostream<..> &os, unsigned_int<...> & uint
);

This operator reads its right hand side from the input stream.

Tests

Vanilla

unsigned_int< 256 > a;
unsigned u;

char const data[] = "1234";
istringstream ss( data ), iss( data );
ss >> a;
iss >> u;

std::cout << a << " <> " << u << "\n";

CHECK( a == u );
STREAM_CHECK( ss, iss );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

1234 <> 1234
Ok

Decimal (Not Hex)

unsigned_int< 256 > a;
unsigned u;

char const data[] = "1234ABCDEF";
istringstream ss( data ), iss( data );
ss >> a;
iss >> u;

std::cout << a << " <> " << u << "\n";

CHECK( a == u );
STREAM_CHECK( ss, iss );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

1234 <> 1234
Ok

Hexadecimal

unsigned_int< 256 > a;
unsigned u;

char const data[] = "12AB3";
istringstream ss( data ), iss( data );
ss >> hex >> a;
iss >> hex >> u;

std::cout << hex << a << " <> " << u << dec << "\n";

CHECK( a == u );
STREAM_CHECK( ss, iss );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

12ab3 <> 12ab3
Ok

Octal

unsigned_int< 256 > a;
unsigned u;

char const data[] = "0765";
istringstream ss( data ), iss( data );
ss >> oct >> a;
iss >> oct >> u;

std::cout << hex << a << " <> " << u << dec << "\n";

CHECK( a == u );
STREAM_CHECK( ss, iss );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

1f5 <> 1f5
Ok

Large Input

unsigned_int< 256 > a;
unsigned u;

char const data[] = "987654321098765432109876543210";
istringstream ss( data );

ss >> a;

CHECK( ! ss.fail() );
CHECK( ss.eof()  );

std::cout << a << "\n";

CHECK( a == unsigned_int< 256 >( data ) );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

987654321098765432109876543210
Ok