lc.2
- to_string converting int to string
1
2
3
4
#include <string> //remember to include the <string> headfile!
using namespace std;
string s = to_string(42);
#stoi convert string to int
1
stoi( str )
- MY MISUNDERSTANDINGS
```cpp
string str=to_string(x);//convert x to a string
int result =0;
int muti =1;//倍数
for(int i=0;i<str.length();i++){
result =result + str[i]muti;
muti=muti10;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
---
```cpp
string str=to_string(x);//convert x to a string
string result;
for(int i=str.length()-1;i>=0;i--){
result+=str[i];//let the result be a string,too
}
2024-07-27 02:32
This post is licensed under CC BY 4.0 by the author.