#include#include using namespace std; int atoi(string str) { bool negFlag = false; string::iterator my_iter; my_iter = str.begin(); if (str.find("-")==0) { negFlag = true; my_iter++; } int num = 0; while (my_iter!=str.end()) { num*=10; num+=(*my_iter-'0'); my_iter++; } if(negFlag) { num*=-1; } return num; } int main() { string mystr; cout << "Input your sting: " << endl; getline(cin, mystr, '\n'); cout << mystr << endl; cout << atoi(mystr) << endl; cin.get(); return 0; }
Pages
Welcome~~~
This blog: http://alg-code.blogspot.com/
It is easier to write an incorrect program than understand a correct one.
Friday, February 25, 2011
My atoi C++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment