c++ int string互转

1.

    if(i<){
monthNumber = "";
itoa(i+,iCharArray,);
monthNumber += iCharArray;
} else {
itoa(i+,iCharArray,);
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 = ;
string str;
ss<<n;
ss>>str;
// string 转 int
str = "";
n = atoi(str.c_str());
}
上一篇:Java int to String互转


下一篇:NPOI:处理xls文件中的合并行