C++ 将std::string转换为MSVC特定的\uuuu int64

C++ 将std::string转换为MSVC特定的\uuuu int64,c++,C++,我可以知道如何将std::string转换为MSVC特定的\uuu int64吗?这里有一种方法: #include <iostream> #include <string> #include <sstream> using namespace std; int main() { string s( "1234567890987654321"); stringstream strm( s); __int64 x; st

我可以知道如何将std::string转换为MSVC特定的\uuu int64吗?

这里有一种方法:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
    string s( "1234567890987654321");

    stringstream strm( s);

    __int64 x;

    strm >> x;

    cout << x;

}
#包括
#包括
#包括
使用名称空间std;
int main(){
字符串s(“1234567890987654321”);
stringstream strm(s);
__int64x;
strm>>x;
cout


另请参见此链接(尽管它适用于linux/unix):

\uu int64
,虽然是扩展名,但仍然只是一个数字类型。请使用通常使用的方法

Boost是我最喜欢的。它以一种易于使用的形式概括了Michaels的答案:

__int64 x = boost::lexical_cast<__int64>("3473472936");
在任何平台上获取
int64
,而无需更改代码

__int64 x = boost::lexical_cast<__int64>("3473472936");
template <typename R>
const R lexical_cast(const std::string& s)
{
    std::stringstream ss(s);

    R result;
    if ((ss >> result).fail() || !(ss >> std::ws).eof())
    {
        throw std::bad_cast();
    }

    return result;
}
#include <boost/cstdint.hpp>
typedef boost::int64_t int64;