C++ 字符串库函数整理
来源:互联网 发布:xp动态壁纸软件 编辑:程序博客网 时间:2024/05/22 09:48
<span style="font-size:18px;">#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sstream>using namespace std;int sToI(string s){ //字符串转为 int int myInt; istringstream buffer(s); buffer>>myInt; return myInt;}string iToS(int myInt){ //int 转为字符串 ostringstream buffer; buffer<<myInt; return buffer.str();}void PrintStr(const char* str) { cout<<str<<endl;}//将字符串翻转void PrintRevStr(char* str) { cout<<strrev(str)<<endl;}int main() { //字符串转化为数字,需要stdlib.h char a[] = "-100.23"; char b[] = "200.00"; float c = atof(a) + atof(b); cout<<c<<endl; //数字转化为字符串 char buffer[50]; int int_1 = 10020030; //sprintf,需要stdio.h sprintf(buffer, "%d", int_1); cout<<buffer<<endl; //itoa,注意:两种方法对buffer的影响不叠加 itoa(int_1, buffer, 10); cout<<buffer<<endl; //string转化为const char* string str_1 = "abcde"; const char* char_1 = str_1.c_str(); PrintStr(char_1); char str_2[] = "abcdefg"; PrintRevStr(str_2); char s[] = "abcde"; strrev(s); cout<<s<<endl;}</span>
0 0
- C++ 字符串库函数整理
- C字符串处理库函数
- c/c++库函数整理1
- 归纳整理Linux下C语言常用的库函数----内存及字符串控制及操作
- C 字符串 库函数 的实现
- c库函数之分割字符串
- 仿写c字符串库函数
- C语言字符串相关库函数
- 数字转化为字符串的库函数整理
- c语言快速排序的库函数整理
- C语言整理:几个库函数的学习
- 【C/C++】库函数中的字符串函数
- C语言字符串处理的库函数
- C库函数中字符串处理函数集合
- 迅雷笔试 字符串反转 C库函数 strrev
- C库函数中字符串处理函数集合
- C语言字符串操作常用库函数
- 操纵 C 风格字符串的标准库函数
- About RAID
- [Win32]重绘的基本概念以及简单的文本输出文本输出
- 今日头条 频道管理(删除、添加、拖动)
- 2014牡丹江现场赛A题D题I题(水,概率Dp,水)ZOJ 3819,3822,3827
- c#操作串口
- C++ 字符串库函数整理
- windows cygwin安装ssh
- 专业版PDF转换器的优势所在
- 【Stackoverflow好问题】StringBuilder和StringBuffer对比
- python如何import 文件名存在字符串变量里的module
- eclipse用maven打可执行的jar包
- 树型递归在BOM中测算可用量的范例
- Android手机的屏幕大小和密度
- 浅谈堆栈问题-C++