Logo

Programming-Idioms

  • Go
  • C++
  • Fortran
read (unit=s,fmt=*) i
import "strconv"
i, err  := strconv.Atoi(s) 

Atoi(s) is shorthand for ParseInt(s, 10, 0). It yields type int.
import "strconv"
i, err := strconv.ParseInt(s, 10, 0)

Radix 10. The third argument 0 means "fit in implementation-specific int". But the result type is always int64.
Don't ignore the potential error err !
#include <string>
int i = std::stoi(s);
#include <cstdlib>
int i = std::atoi(s);

s is a char*
#include <string>
#include <sstream>
std::stringstream ss(str);
int i;
ss >> i;
std::string s("123");
int i;
std::from_chars(s.data(), s.data() + s.size(), i, 10);
I : Integer := Integer'Value (s);

New implementation...