0
0

More than 1 year has passed since last update.

fmt.Printfは中身をstringしないとエラーになる

Posted at

go言語でfmt.Printfを扱う時にint型を表示しようとしてエラー出してしまうので、備忘録


package main

import (
    "fmt"
    "strconv"
)

func main() {

    var s string = "5"
        // int型に変換
    i, _ := strconv.Atoi(s)

    fmt.Printf(i)  # こちらはエラーになる
    // fmt.Printf("%v", i) # こちらはエラーにならない

}

実行結果


# command-line-arguments
.\main.go:17:12: cannot use i (type int) as type string in argument to fmt.Printf   

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0