int main() {
int val = 10;
// int -> string
string s = to_string(val);
// str -> int
int i = atoi(s.c_str());
// str -> float
double f = atof(s.c_str());
// str -> long
long l = atol(s.c_str());
// 下面的方法也可将string转换为数值类型,但在leetcode中编译不通过,本地CLion可用。
i = stoi(s);
f = stof(s);
l = stol(s);
return 0;
}
C++ string 和 int, float double long数据类型的转换
最新推荐文章于 2023-06-21 10:22:20 发布