int转string(注:itoa不是标准函数,OJ平台可能不接受)

int n = 10;
char temp[32];
string str;
 
sprintf(temp, "%d", n);
str = temp;

or

string str = to_string(n);

注意:to_string(int n) 是11版新C++标准。如果老版编译器应该写成

string str = to_string((long long)n);

 

 

string转int

string str = "test";
int n = atoi(str.c_str());

 

相关文章:

  • 2021-10-12
  • 2021-10-22
  • 2021-06-19
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2021-07-09
  • 2021-11-25
  • 2022-12-23
  • 2022-03-05
相关资源
相似解决方案