Skip to content

Commit 794eccd

Browse files
committed
new snippet - string to int
1 parent 11625c1 commit 794eccd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: String Int
3+
description: Converts string to int without built in stoi()
4+
author: Emosans
5+
tags: string,int
6+
---
7+
8+
```cpp
9+
std::int to_num(const std::string& input){
10+
int num=0;
11+
int len=input.size();
12+
for(int i=0;i<len;i++){
13+
num=num*10+(input[i]-'0');
14+
}
15+
return num;
16+
}
17+
18+
// Usage
19+
to_num("123"); // Returns 123(type->int)
20+
```

0 commit comments

Comments
 (0)