#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;
}

string 与 int double 的转化的更多相关文章

  1. string,char*,int 之间的转化

    c++中经常遇到string,char*,int之间的相互转化,今天就来整理一下. 以下是转载并修改的内容: 以下是常用的几种类型互相之间的转换 string 转 int先转换为char*,再使用at ...

  2. java中String和int的互相转化

    1. String 转 int 方式1:Integer.parseInt(); 方式2: Integer.valueOf(myStr).intValue(); 2.  int 转String 方式1: ...

  3. 如何将std::string转int,double? (C/C++) (C) (template)

    http://www.cnblogs.com/oomusou/archive/2008/08/01/525647.html http://blog.sina.com.cn/s/blog_a843a88 ...

  4. .build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)'

    CXX/LD -o .build_release/tools/convert_imageset.bin.build_release/lib/libcaffe.so: undefined referen ...

  5. String和int、long、double等基本数据类型的转换

    学习目标: 掌握Java的基本数据类型与String的转换 学习内容: 1.转化规则 String 转 基本数据类型 基本数据类型 变量 = 包装类.Parse基本数据类型(String); // c ...

  6. 已知有一个Worker 类如下:  public class Worker  { private int age;  private String name;  private double salary;  public Worker (){}  public Worker (String nam

    package homework006; public class Worker { private int age; private String name; private double sala ...

  7. java中string和int互相转化

    1 怎样将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

  8. java中string和int互相转化 (转)

    1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

  9. string和int互相转化

    1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

随机推荐

  1. es6 promise 所见

    一.Promise是什么? Promise 是异步编程的一种解决方案: 从语法上讲,promise是一个对象,从它可以获取异步操作的消息:从本意上讲,它是承诺,承诺它过一段时间会给你一个结果. pro ...

  2. 5 Successful Business Models for Web-Based Open-Source Projects

    https://handsontable.com/blog/articles/2016/3/5-successful-business-models-for-web-based-open-source ...

  3. [Luogu 2386]放苹果

    Description 题库链接 把 \(n\) 个同样的苹果放在 \(m\) 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分发.多测,数据组数 \(t\). \(1\leq m,n\le ...

  4. 字符串翻转(C++)

    1.字符串原地翻转,"abc"->"cba": int str_reverse(string &str,int first,int last) { ...

  5. Prisma 2 is Coming Soon

    转自:https://www.prisma.io/blog/prisma-2-is-coming-soon-mwwfhevie993 Prisma 2 will introduce many fund ...

  6. shell test条件检查

    Shell test 命令 Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 数值测试 参数 说明 -eq 等于则为真 -ne 不等于则为真 -gt ...

  7. Jedis:Exception in thread "main" java.lang.VerifyError: Bad type on operand stack

    Exception in thread "main" java.lang.VerifyError: Bad type on operand stackException Detai ...

  8. sublime text 3插件改造之添加从模版新增文件到指定目录

    简介:以前使用ST2里面的Sublime NFFT插件比较顺手,最近安装了ST3,但是Sublime NFFT插件不支持ST3,就下载了SublimeTmpl从模版新建文件插件.在使用时,习惯在侧边栏 ...

  9. javascript中的indexOf与if判断的装逼写法

    常规indexOf与if判断写法: if("112233".indexOf("22")>-1) { console.log("很二") ...

  10. Codeforces 1163E Magical Permutation [线性基,构造]

    codeforces 思路 我顺着图论的标签点进去的,却没想到-- 可以发现排列内每一个数都是集合里的数异或出来的. 考虑答案的上界是多少.如果能用小于\(2^k\)的数构造出\([0,2^k-1]\ ...