#include "stdafx.h"
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<stdio.h>
#include<stdlib.h> using namespace std; //sstream
string int2str1(int n){
ostringstream oss;
oss << n;
string s = oss.str();
return s;
} //sprintf
string int2str2(int n){
char temp[];
sprintf_s(temp, "%d", n);
string str = temp;
return str;
} //sstream
int str2int1(string s){
int n;
istringstream iss;
iss.clear();
iss.str(s);
iss >> n;
return n;
} //sscanf
int str2int2(string s){
int n;
sscanf_s(s.c_str(), "%d", &n); //scanf前面加s用于把str输入到n中
return n;
} //stoi
int str2int3(string s, int base){ // base:进制
int n = stoi(s, nullptr, base);
return n;
} //c_str
const char* str2Cchar(string s){
//const char* ss = s.c_str(); //出错,因为s会被析构,ss指向垃圾内容
char c[];
strcpy_s(c, s.c_str()); return c;
} //atoi
int Cchar2int(const char* s){
//char buffer[100];
int n = atoi(s);
return n;
} char* int2char(int n){
char buffer[];
_itoa_s(n, buffer, );
return buffer;
} int _tmain(int argc, _TCHAR* argv[])
{
//cout << str2int1("1234") << endl;
//cout << str2int2("1234") << endl;
//cout << int2str1(1234) << endl;
//cout << int2str1(1234) << endl; //string s1 = "123455";
//const char* ss1 = str2Cchar(s1); //char s2[] = "123455";
//const char* ss2 = s2;
//cout << Cchar2int(ss2) << endl; char* c = int2char();
cout << *c << endl; return ;
}

【C++】int、const char*、char*、char、string之间的转换的更多相关文章

  1. java字符数组char[]和字符串String之间的转换

    java字符数组char[]和字符串String之间的转换 觉得有用的话,欢迎一起讨论相互学习~Follow Me 使用String.valueOf()将字符数组转换成字符串 void (){ cha ...

  2. char* 、const char*和string之间的转换

    1. const char* 和string 转换 (1) const char*转换为 string,直接赋值即可.     EX: const char* tmp = "tsinghua ...

  3. C#中char[]与string之间的转换;byte[]与string之间的转化

    目录 1.char[]与string之间的转换 2.byte[]与string之间的转化 1.char[]与string之间的转换 //string 转换成 Char[] string str=&qu ...

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

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

  5. 基本数据类型、包装类、String之间的转换

    package 包装类; /** *8种基本数据类型对应一个类,此类即为包装类 * 基本数据类型.包装类.String之间的转换 * 1.基本数据类型转成包装类(装箱): * ->通过构造器 : ...

  6. 如何在Byte[]和String之间进行转换

    源自C#与.NET程序员面试宝典. 如何在Byte[]和String之间进行转换? 比特(b):比特只有0 1,1代表有脉冲,0代表无脉冲.它是计算机物理内存保存的最基本单元. 字节(B):8个比特, ...

  7. c# String ,String[] 和 List<String>之间的转换

    C#对字符串进行处理时,经常需要进行String,String[]和List<String>之间的转换 本文分析一下它们的差异和转换 一. 1. String > String[] ...

  8. C++ char float int string 之间的转换

    string str = "123"; string 转 int int i = atoi( str.c_str() ); string 转 float float f = ato ...

  9. C#中char[]与string之间的转换

    string 转换成 Char[] string ss = "abcdefg"; char[] cc = ss.ToCharArray(); Char[] 转换成string st ...

随机推荐

  1. 如何查看项目svn路径

    1.选择项目根目录---->鼠标右键---->属性---->版本控制(Subversion) 如图:

  2. storm源码之storm代码结构【译】【转】

    [原]storm源码之storm代码结构[译]  说明:本文翻译自Storm在GitHub上的官方Wiki中提供的Storm代码结构描述一节Structure of the codebase,希望对正 ...

  3. 学习编写Windows Live Writer插件

    1.参考链接 参考:http://www.cnblogs.com/liulun/archive/2009/05/27/1491116.html Live Writer API参考:http://msd ...

  4. flexbox布局的兼容性

    http://ayqy.net/blog/flexbox布局的兼容性/ 写在前面 flex布局早在2009年就有了,而现在是2015年6月8日,使用最新的flex语法会发现支持程度并不好,即使是在“高 ...

  5. ajax与HTML5 history pushState/replaceState实例

    一.本文就是个实例展示 三点: 我就TM想找个例子,知道如何个使用,使用语法什么的滚粗 跟搜索引擎搞基 自己备忘 精力总是有限的,昨天一冲动,在上海浦东外环之外订了个90米的房子,要借钱筹首付.贷款和 ...

  6. HDU 2822 (BFS+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同 ...

  7. 移动端页头推荐配置 出现找不到favicon.ico错误原因和解决方法

    favicon 在未指定 favicon 时,大多数浏览器会请求 Web Server 根目录下的 favicon.ico .为了保证 favicon 可访问,避免404,必须遵循以下两种方法之一: ...

  8. 将类似 12.56MB 36.89KB 转成 以K为单位的数字【备忘】

    select case RIGHT(RESOURCE_SIZE,2) when 'MB' THEN SUBSTRING_INDEX(RESOURCE_SIZE,'MB',1)*1024 ELSE SU ...

  9. ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector

    NBUT 1646 Internet of Lights and Switches Time Limit:5000MS     Memory Limit:65535KB     64bit IO Fo ...

  10. OI刷题记录

    从六月一号开始记录啦 6月1日 link-cut-tree BZOJ2631 tree