string型をint型に変換する
#include <cstdlib> // atoi, atol, atof用 #include <string> // string用 string str1 = "117"; string str2 = "34899"; string str3 = "997582646647"; cout << atoi( str1.c_str() ); // 文字列全体をint型に変換 cout << atol( str2.c_str() ); // 文字列全体をlong型に変換 cout << atof( str3.c_str() ); // 文字列全体をfloat型に変換 // 1文字ずつ取り出してint型に変換する // アスキーコードの引き算をして数値を求める cout << (int) str[0] - (int) '0';