C++11以上であれば
STLに
数を文字列に変換する
文字列を数字に変換する
main.cpp
STLに
数を文字列に変換する
to_string(数字);と
文字列を数字に変換する
int型整数 = stoi(文字列); float型実数 = stof(文字列); double型実数 = stod(文字列);があります
main.cpp
#include <iostream> #include <string> using namespace std; int main() { int a1 = 500; string s1 = to_string(a1); cout << s1 << endl; int b1 = stoi(s1); b1 *= 2; cout << b1 << endl; string a2 = "3.14"; float f1 = stof(a2); cout << f1 << endl; }
コメントをかく