#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
//string -> int float double
string str = "088.123";
cout << "string -> int float double" << endl;
cout << atoi(str.c_str()) << endl;
cout << atol(str.c_str()) << endl;
cout << atof(str.c_str()) << endl;
int a;
float b;
double c;
istringstream iss(str);
iss >> a >> b >> c;
cout << a << " " << b << " " << c << endl;
//int double float -> string
a = 10;
b = 10.123;
c = 100.234;
cout << "int double float -> string" << endl;
cout << to_string(a) << " " << to_string(b) << " " << to_string(c) << endl;
stringstream ss;
ss << a << " " << b << " " << c;
cout << ss.str() << endl;
return 0;
}
相关文章
- 【Linux】CentOS7 alien命令 转化deb 与 rpm的相互转化
- BigDecimal与String之间的转换
- String a ="aa"与String a = new String("aa")之间的区别
- Java 中Int转String的三种方法
- Java中int转String类型的三种方法
- java实现斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。 n public class Solution_feibonaqi { public int Fibonacci(int n) { int result[] = { 0, 1 }; if (n < 2) { return result[n]; } int f0 = 0; int f1 = 1; int f2 = 0; for (int i = 2; i <= n; i++) { f2 = f1 + f0; f0 = f1; f1 = f2; } return f2; } public static void main(String[] args) { Scanner sc = new Scanner; int n = ; Solution_feibonaqi fei = new Solution_feibonaqi; ((n)); } }
- Java中int与String相互转换的方法
- javascript——js string 转 int 注意的问题——parseInt
- Java中Date转换为Datetime、String与Date的相互转换
- char * ,char,string与NSString转化(objec-c与c++混编基础)