c++转string
//实现to_string函数 #include
#include
using namespace std; #define max 100 string to_String(int n) { int m = n; char s[max]; char ss[max]; int i=0,j=0; if (n < 0)// 处理负数 { m = 0 - m; j = 1; ss[0] = '-'; } while (m>0) { s[i++] = m % 10 + '0'; m /= 10; } s[i] = '\0'; i = i - 1; while (i >= 0) { ss[j++] = s[i--]; } ss[j] = '\0'; return ss; } int main() { cout << "请输入整数:"; int m; cin >> m; string s = to_String(m) + "abc"; cout << s << endl; system("pause"); return 0; }
第一种方法:
- int i=0;
- char itc[10];
- sprintf(itc,“%d.bmp”,i);
第二种方法:
int i=5;
char err_str[10];
_itoa(i, err_str, 10); //
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/177655.html原文链接:https://javaforall.net
