c++ string转int,int 转string,类型转换
来源:互联网 发布:js excel 展示 编辑:程序博客网 时间:2024/06/04 23:33
#include<iostream>
#include <stdlib.h>
#include <sstream>
using namespace std;
void int2str(const int &int_tmp, string& string_tmp)
{
stringstream stream;
stream << int_tmp;
stream >> string_tmp;
}
void str2int(const string & string_tmp, int & int_tmp)
{
string str = string_tmp;
for (int i = 0; i < str.size(); ++i)
{
const char c = str.c_str()[i];
if (c < '0' || c > '9')
{
int_tmp = 2222;
return;
}
}
stringstream stream(string_tmp);
stream >> int_tmp;
}
int main()
{
int a = 0;
string str;
int2str(a, str);
cout << str << endl;
int b;
string str1("1452");
str2int(str1, b);
cout << b << endl;
string ssss = "";
if (ssss.empty())
{
cout << "w cao" << endl;
}
else
{
cout << "w ri" << endl;
}
cin.get();
cin.get();
return 0;
#include <stdlib.h>
#include <sstream>
using namespace std;
void int2str(const int &int_tmp, string& string_tmp)
{
stringstream stream;
stream << int_tmp;
stream >> string_tmp;
}
void str2int(const string & string_tmp, int & int_tmp)
{
string str = string_tmp;
for (int i = 0; i < str.size(); ++i)
{
const char c = str.c_str()[i];
if (c < '0' || c > '9')
{
int_tmp = 2222;
return;
}
}
stringstream stream(string_tmp);
stream >> int_tmp;
}
int main()
{
int a = 0;
string str;
int2str(a, str);
cout << str << endl;
int b;
string str1("1452");
str2int(str1, b);
cout << b << endl;
string ssss = "";
if (ssss.empty())
{
cout << "w cao" << endl;
}
else
{
cout << "w ri" << endl;
}
cin.get();
cin.get();
return 0;
}
欢迎各位提出意见或者新的方法,交流群:569624724
0 0
- c++ string转int,int 转string,类型转换
- string转换成int类型 和int转string
- [转]string, char*, int类型转换
- 【转】string, char*, int类型转换
- C/C++ string类型转换int类型
- C++:int转string
- c++int转string
- C++int转string
- String类型转int类型
- c++string类型转换为int型
- string类型转换int类型
- string类型转换int类型
- Grails string转int类型
- int转string、wstring类型
- java String转Int类型
- string, char*, int类型转换
- string, char*, int类型转换
- int转换成string类型
- ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法(日志已满)
- spark on yarn 集群 安装
- JAVA相关基础知识
- 完美卸载JDK
- 微咖云集
- c++ string转int,int 转string,类型转换
- 2016校招互联网公司薪资大全
- php封装的mysqli类完整实例
- Material Design
- SQLLite优化
- 看php爬虫---小感
- linux编程yum命令(下)
- servlet与javabean的区别&有两种javabean
- Python中的操作符/表达式