Advertisement
MeehoweCK

Untitled

Jul 30th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int stringtoint(string liczba)
  7. {
  8.     int wynik = 0, potega = 1;
  9.  
  10.     for(int i = (liczba.size() - 1); i >= 0; --i)
  11.     {
  12.         wynik += (static_cast<int>(liczba[i]) - 48) * potega;
  13.         potega *= 10;
  14.     }
  15.  
  16.     return wynik;
  17. }
  18.  
  19. int main()
  20. {
  21.     string liczba = "15716";
  22.     int iliczba = stringtoint(liczba);
  23.     cout << iliczba << endl;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement