Avatar ·

How to convert a string to a number (int) in Go? Error handling and examples

Hi everyone! I just started learning Go and ran into a problem converting a string to an integer. I'm writing a simple calculator that takes two numbers from the command line as strings and should add them. But I can't figure out how to properly convert a string to int. Here's my code: ```go package main import ( "fmt" "os" ) func main() { if len(os.Args) != 3 { fmt.Println("Usage: calculator ") return } a := os.Args[1] b := os.Args[2] // Trying to add, but getting an error sum := a + b // This is string concatenation, not addition! fmt.Println("Sum:", sum) } ``` I understand that `a + b` just concatenates strings, not adds numbers. In other languages I used `int()` or `parseInt()`, but in Go this is