CHAR*を長いロング(64ビット)にクロスプラットフォームする方法は?

StackOverflow https://stackoverflow.com/questions/7388410

質問

char*文字列を長い(64ビット)整数に変換するにはどうすればよいですか?

MSVCとGCCコンパイラを使用しており、プラットフォームはWindows、Linux、Mac OSです。

ありがとう。

役に立ちましたか?

解決

使用する strtoull 署名されていない長い長いまたは strtoll 長い署名のために。任意のUnix(Linux、Mac OS X)、タイプ man strtoull また man strtoll その説明を取得します。どちらもC99標準の一部であるため、Cをサポートするシステムで利用できるはずです。 それらの使用方法について例を持っています.

他のヒント

サポートするコンパイラを備えたC ++の場合 long long int, 、aを使用します std::istringstream 物体。例えば:

char* number_string;
//...code that initializes number_string

std::istringstream input_stream(number_string);
long long int i64_bit_type;
input_stream >> i64_bit_type;
long long int i;

if(sscanf(string, "%lld", &i) == 1) { ... }

boost::lexical_cast おそらく最も単純な(コード内)。見る http://www.boost.org/doc/libs/1_47_0/libs/conversion/lexical_cast.htm 詳細については。交互に使用します stringstream 数値を解析します。

 #include <stdlib.h>

 char serial[1000];

 long long var = _atoi64(serial);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top