1.
if(i<9){ monthNumber = "0"; itoa(i+1,iCharArray,10); monthNumber += iCharArray; } else { itoa(i+1,iCharArray,10); monthNumber = iCharArray; }
2.
int转string
int n = 0;
std::stringstream ss;
std::string str;
ss<<n;
ss>>str;
string转int
std::string str = "123";
int n = atoi(str.c_str());
#include "stdafx.h" #include <string> #include <sstream> using namespace std; void main() { // int 转 string stringstream ss; int n = 123; string str; ss<<n; ss>>str; // string 转 int str = "456"; n = atoi(str.c_str()); }
时间: 2024-10-10 09:32:47