-
Notifications
You must be signed in to change notification settings - Fork 0
/
strlib.cpp
32 lines (31 loc) · 937 Bytes
/
strlib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <sstream>
#include <fstream>
#include "strlib.h"
int parseInt(std::string input){
bool isItNegative=false;
int number=0;
if(input.size()==0)return 0;
if(input[0]=='-')isItNegative=true;
for(int i=isItNegative?1:0;(unsigned)i<input.size();i++){
if(input[i]>='0'&&input[i]<='9'){
number=number*10+input[i]-'0';
}else return 0;
}
return isItNegative?-number:number;
}
std::string intToString(const int& input){
std::ostringstream myCustomStreamString;
myCustomStreamString<<input;
return myCustomStreamString.str();
}
bool isInt(std::string input){
bool isItNegative=false;
int number=0;
if(input.size()==0)return false;
if(input[0]=='-')isItNegative=true;
for(int i=isItNegative?1:0;(unsigned)i<input.size();i++){
if(input[i]>='0'&&input[i]<='9'){
}else return false;
}
return true;
}