//float转string

char a[100];
float b = 1.234;
sprintf(a, "%f", b);
string result(a);
//int转string,利用sprintf
int main(){
int mm = 2414;
char *ch = new char; //或者char ch[256];
string tmp;
sprintf(ch,"%d",mm); //sprintf(ch, "%f", mm)将float转string
tmp = ch;
cout << tmp + "124124";
cin >> mm;
}
//利用c_str将sting 转为 const char*, 一般不会要求将const char*转为char*,如果要转,先考虑函数设计问题

string s = "test";
const char* = s.c_str();
//char* 或者char数组转string,直接利用构造函数char *offpath = new char[100];
ifstream inff("C:\\model.txt",ios::in);
while(!inff.eof()){
inff.getline(offpath,100);
string stmp(offpath);
}

C++中int,float,string,char*的转换(待续)的更多相关文章

  1. java中int和String之间的转换

    String 转为int int i = Integer.parseInt([String]); int i = Integer.valueOf(my_str).intValue(); int转为St ...

  2. Java中int和String类型之间转换

    int –> String int i=123; String s=""; 第一种方法:s=i+""; //会产生两个String对象 第二种方法:s=S ...

  3. 速战速决 (2) - PHP: 数据类型 bool, int, float, string, object, array

    [源码下载] 速战速决 (2) - PHP: 数据类型 bool, int, float, string, object, array 作者:webabcd 介绍速战速决 之 PHP 数据类型 boo ...

  4. C++中int与string的转化

    C++中int与string的转化 int本身也要用一串字符表示,前后没有双引号,告诉编译器把它当作一个数解释.缺省情况下,是当成10进制(dec)来解释,如果想用8进制,16进制,怎么办?加上前缀, ...

  5. java中int,float,long,double取值范围,内存泄露

    java中int,float,long,double取值范围是多少? 写道 public class TestOutOfBound { public static void main(String[] ...

  6. java和js中int和String相互转换常用方法整理

    java中int和String的相互转换常用的几种方法: int  > String int i=10;String s="";第一种方法:s=i+""; ...

  7. java中Integer 和String 之间的转换

    java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...

  8. c++ 中double与string之间的转换,char *

    运行代码为 /* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> //#inc ...

  9. C++11中int,float,double与string的转化

    在C++11中可以使用std::to_string()函数将数值转换为string格式,十分方便. 以下部分来选自cplusplus.com. std::to_string string to_str ...

随机推荐

  1. Cadence 建立封装:多个引脚于芯片内部连接的封装建立方式

    Ti 家有一种片子,型号为CSD19534Q5A.此芯片的外观样式如图: 可以看到,这个片子共有8个引脚,其中5.6.7和8这四个引脚的内部是连接在一起的. Ti 在数据手册中也介绍了封装的样式: 下 ...

  2. 如何解决xml在eclipse下的拼写报错

    进入preferences——键入“spelling”——看到勾选框:Enable spelling check,去掉勾选框,可消除eclipse下的拼写错误

  3. Linq的TakeWhile误用

    where(func<>)返回符合条件的元素 与此相对的skipwhile跳过符合条件的,返回剩下的元素 容易误用的takewhile,与where 不一样,只有当所有元素满足条件时,才返 ...

  4. MySQL修改,表结构大幅修改

    ------------------create table t_video_file_temp( video_id bigint not null comment '视频Id', file_md5 ...

  5. XML 简介

    什么是 XML? XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 HTML XML 的设计宗旨是传输数据,而非显示数据 XML 标签没 ...

  6. java设计模式(八) 适配器模式

    [适配器模式]将一个类的接口,转换成客户期望的另外一个接口.适配器让原本接口不兼容的类可以合作无间. 1,Duck接口 package com.pattern.adapter; public inte ...

  7. 网站(logo,主机)

    logo生成网站  http://www.uugai.com/ 花生壳 http://hsk.oray.com/download/

  8. cygwin-使用介绍

    cygwin使用: 使用上的方便性很是不错,启动Cygwin以后,会在Windows下得到一个Bash Shell,由于Cygwin是以Windows下的服务运行的,所以很多情况下和在Linux下有很 ...

  9. Leetcode 130. Surrounded Regions

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...

  10. Linux安装后的基本配置

    1.换源 http://mirrors.zju.edu.cn http://mirrors.aliyun.com http://mirrors.ustc.edu.cn ubuntu替换/etc/apt ...