2017-02-21 141 views

回答

6

你嘗試

uint64_t value; 
std::istringstream iss("18446744073709551610"); 
iss >> value; 

Live Demo


這可能對於過時的標準工作了。

5

如果您使用C++ 11或更高版本,請嘗試std::stoull

This post也可能有幫助。因爲其他的問題是關於C.

+0

那麼,C++ 11可以被認爲是幾年以來的現行標準。 –

+1

它是* a *標準,但不是**標準。由於工作或遺留代碼或其他原因,仍然有很多人正在使用C++ 03。 – Gambit

+0

當然** **標準是C++ 14? –

2

如果你使用升壓我沒有這個標記爲重複的,你可以利用boost::lexical_cast

#include <iostream> 
#include <string> 
#include <boost-1_61/boost/lexical_cast.hpp> //I've multiple versions of boost installed, so this path may be different for you 

int main() 
{ 
    using boost::lexical_cast; 
    using namespace std; 

    const string s("2424242"); 
    uint64_t num = lexical_cast<uint64_t>(s.c_str()); 
    cout << num << endl; 

    return 0; 
} 
+0

我沒有使用boost – Cauchy

+2

下一位讀者可能仍然是一個有用的答案。 –

+0

@BaummitAugen Hhhhhm,_'lexical_cast'_跳到這裏有用嗎? –