3

I'm trying to extract different types of data from a string.

void                    readHeader(char buf[BUFFSIZE])
{
  std::istringstream    hdr(buf);
  __uint128_t           id_client;

  hdr >> id_client; // doesn't compile
}

I'm getting this error when I do that hdr >> id_client :

Unix/UnixSocket.cpp:158:10: error: ambiguous overload for ‘operator>>’ in ‘hdr >> id_client’ Unix/UnixSocket.cpp:158:10: note: candidates are: In file included from /usr/include/c++/4.7/sstream:39:0,
                 from Unix/UnixSocket.cpp:11: /usr/include/c++/4.7/istream:118:7: note: std::basic_istream<_CharT,
_Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT,
_Traits>::__istream_type = std::basic_istream<char>] <near match> /usr/include/c++/4.7/istream:118:7: note:   no known conversion for argument 1 from ‘__int128 unsigned’ to ‘std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&) {aka std::basic_istream<char>& (*)(std::basic_istream<char>&)}’ /usr/include/c++/4.7/istream:122:7: note: std::basic_istream<_CharT,
_Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT,
_Traits>::__istream_type = std::basic_istream<char>; std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios<char>] <near match> /usr/include/c++/4.7/istream:122:7:

Is there any way to properly store my id_client in this __uint128_t variable ?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Amina
  • 404
  • 4
  • 14
  • 2
    As the type is not a standard type, the standard library have no support for it. You have to parse and convert the number manually. – Some programmer dude Nov 02 '14 at 15:03
  • Maybe you can use `uint128_t` if it is supported by your compiler. – justanothercoder Nov 02 '14 at 15:05
  • @JoachimPileborg I'm pretty sure he is looking for a complement to the standard library from the clang/gcc team as they have added the type into their compilers. It's an interesting question if it can be found. – Daniel O Jan 22 '15 at 09:51

1 Answers1

1

https://gmplib.org/ might help. The mpz_class class of the gmpxx object abstraction supports I/O operators and the mpz_export(...) function allows you to transform the result into an array of bytes. If they exceed 16 bytes you may throw an exception or complain otherwise. Not very fast but I guess fast to implement.

Oncaphillis
  • 1,888
  • 13
  • 15