Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

64bit integer conversion from string

$
0
0

I'm dealing with the problem of reading a 64bit unsigned integer unsigned long long from a string. My code should work both for GCC 4.3 and Visual Studio 2010.

I read this question and answers on the topic: Read 64 bit integer string from file and thougth that strtoull would make the work just fine and more efficiently than using a std::stringstream. Unfortunately strtoullis not available in Visual Studio's stdlib.h.

So I wrote a short templated function:

template <typename T>
T ToNumber(const std::string& Str)
{
    T Number;
    std::stringstream S(Str);
    S >> Number;
    return Number;
}

unsigned long long N = ToNumber<unsigned long long>("1234567890123456789");

I'm worried about the efficiency of this solution so, is there a better option in this escenario?


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>