请问有将string类转化为数字的函数吗?

5499 2003-05-14 07:57:50
string str;
str = "9999";
int i;
怎么样才能把str转化为int或者float double之类
...全文
79 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bm1408 2003-05-14
  • 打赏
  • 举报
回复
今天睡午觉的时候,顺手看了一下书,刚学的!给你!
#include "string"
#include "sstream>
using namespace std;

int main()
{string str;
str="9999";
int i;
double f;
i=atoi(str);
cout<<i;
f=atol(str);
cout<<f;
}






5499 2003-05-14
  • 打赏
  • 举报
回复
解决了 i = atoi(str.c_str());
fangrk 2003-05-14
  • 打赏
  • 举报
回复
#include <string>
#include <sstream>
using namespace std;
...
string str("123");
stringstream ss;
ss<<str;
int i;
ss>>i;
cout>>i;
a_stupid_boy 2003-05-14
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
string str="33";
int i=atoi(str.c_str());
cout<<i;
return 0;
}

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧