TITLE: Fix: "cannot use X (untyped string constant) as int value"
Wrap the untyped string constant in an explicit type conversion to match the expected int type. Go treats string literals as untyped constants, which cannot be implicitly converted to integers.
package main
import (
"fmt"
"strconv"
)
func main() {
// Incorrect: cannot convert string literal to int directly
// value := int("123") // This will fail to compile
// Correct usage for a numeric string:
value, err := strconv.Atoi("123")
if err != nil {
fmt.Println("Error converting string to int:", err)
return
}
fmt.Println("Converted value:", value)
// If you meant to use a number literal but typed quotes by mistake:
valueLiteral := 123 // Remove quotes
fmt.Println("Literal value:", valueLiteral)
}