c怎么将int转换为string
答案:3 悬赏:0 手机版
解决时间 2021-02-26 22:17
- 提问者网友:骑士
- 2021-02-26 11:57
c怎么将int转换为string
最佳答案
- 五星知识达人网友:狂恋
- 2021-02-26 12:14
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <sstream>
using namespace std;
int main ()
{
int aa = 30;
stringstream ss;
ss<<aa;
string s1 = ss.str();
cout<<s1<<endl; // 30
string s2;
ss>>s2;
cout<<s2<<endl; // 30
return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <sstream>
using namespace std;
int main ()
{
int aa = 30;
stringstream ss;
ss<<aa;
string s1 = ss.str();
cout<<s1<<endl; // 30
string s2;
ss>>s2;
cout<<s2<<endl; // 30
return 0;
}
全部回答
- 1楼网友:酒醒三更
- 2021-02-26 13:12
// string转int
string str="12345";
int b=atoi(str.c_str());
// int转string
int n = 65535;
char t[256];
string s;
sprintf(t, "%d", n);
s = t;
基本思想就是将string 和char*还有int联系起来,char*是他们之间的桥梁。
- 2楼网友:北城痞子
- 2021-02-26 12:53
switch判断不要加双引号,switch(j)
是readkey。。不readkey
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯