std::string str("6"); int num = 0; std::stringstream out; out out>>num; 记得加上 #include
//第一种方法:#include #include using namespace std;int main(){ int n = 65535; char t[256]; string s; sprintf(t, "%d", n); s = t; cout #include #include using namespace std;int main(){ int n = 65535; strstream ss; string s; ss > s; cout 评论0 0 0
int到string就是itoa(int,Cstring*,index); 其中,int是要转换的整数,Cstring*是一个用来接收转换结果的缓冲区,index是进制.比如,要把10按10进制转换成字符就是10,如果按16进制转换成字符说法是A.
可以使用sprintf.sprintf(string, "%s", a); 还有 char *itoa(int value, char *string, int radix);
简单,如果已定义int i=1; string x; 则直接用强制转换命令 x = string(i);即可
干吗要全部转换啊,用哪个转换哪个呗. int[] intArray = new int[] { 1, 2, 3, 4, 5 }; string[] strArray = new string[intArray.Length]; for (int index = 0; index < intArray.Length; ++index) { strArray[index] = intArray[index].ToString(); }
可以给字符串直接赋值,atoi(str.c_str() ) ,我最近都是这么用的,没出错啊
// 使用string 函数#include <iostream>#include <string> using namespace std; int main() { char temp[10]; int ii = 110; sprintf(temp, "%d", ii); string s(temp); cout<<s.c_str()<<endl; return 0; }===// 使用stringstream类#include <iostream>#include
int a = 90; char s = a; string s1; s1.c_str(); s1 = s; cout << s1 << endl;
char buf[100];sprintf(buf, "%d", a);string s(buf);这是最简洁的方法当然还可以这样#include <iostream>#include <string>using namespace std;int main(){ int a = 174; string s; while(a) { s = char(a%10+'0') + s; a/=10; } cout << s << endl; return 0;}