#include <cstdlib>
/*
c言語の文字列を double 型の数値に変換する
x = atof( "3.1415" );
x = atof( str.c_str() );
*/
double atof( const char *nptr );
/*
c言語の文字列のはじめの数値部分を int/long/long long 型の数値に変換する
n = atoi( str.c_str() )
n = atol( str.c_str() )
n = atoll( str.c_str() )
str = "100hoge";
n = atoll( str.c_str() ) ;
Result: n = 100
*/
int atoi( const char *nptr );
long atol( const char *nptr );
long long atoll( const char *nptr );
/*
c言語の文字列のはじめの数値部分をdouble/long double型に変換する
認識可能な形式
-> [符号(+ or -)] 空でない 10 進数字の列 [指数部]
-> [符号(+ or -)] 空でない 16 進数の列 [2 進指数部]
-> [符号(+ or -)] INF or INFINITY
-> [符号(+ or -)] NAN or NAN
string str("3.14hoge");
char *endptr;
const char* ptr = str.c_str();
double x = strtod(ptr, &endptr);
printf("ptr = %s\nendptr = %s\n", ptr, endptr);
printf("x = %.2f\n", x);
ptr = endptr;
printf("ptr = %s\n", ptr);
Result:
ptr = 3.14hoge
endptr = hoge
x = 3.14
ptr = hoge
*/
double strtod( const char* nptr, char** endptr );
long double strtold( const char* nptr, char** endptr );
/*
基数を指定して文字列をlong型に変換する
string str("hoge123huga");
const char* p = str.c_str();
p +=4;
char *e;
long x = strtol( p, &e, 10 );
p = e;
cout << x << endl;
while(*p!='\0') cout << *p++;
cout << endl;
Result:
123
huga
*/
long strtol( const char* nptr, char** endptr, int base );
long long strtoll( const char* nptr, char** endptr, int base );
unsigned long strtoul( const char* nptr, char** endptr, int base );
unsigned long long strtoull( const char* nptr, char** endptr, int base );
/*
絶対値を取得しint/long/long long型で返す
*/
int abs( int j );
long labs( long j );
long long llabs( long long j );
/*
マクロ
*/
NULL, EXIT_SUCCESS, EXIT_FAILURE
最終更新:2013年09月25日 12:45