3
我試圖從字符串中提取不同類型的數據。使用字符串流將字符串轉換爲__uint128_t
void readHeader(char buf[BUFFSIZE])
{
std::istringstream hdr(buf);
__uint128_t id_client;
hdr >> id_client; // doesn't compile
}
我得到這個錯誤,當我做到這一點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:
有什麼辦法妥善我id_client
存儲在這個__uint128_t
變量?
由於類型不是標準類型,因此標準庫不支持它。你必須手動解析和轉換數字。 – 2014-11-02 15:03:34
如果編譯器支持它,也許你可以使用'uint128_t'。 – justanothercoder 2014-11-02 15:05:04
@JoachimPileborg我很確定他正在尋找來自clang/gcc團隊的標準庫的補充,因爲他們已經將類型添加到他們的編譯器中。如果能找到它,這是一個有趣的問題。 – 2015-01-22 09:51:28