Skip to content

Latest commit

ย 

History

History
79 lines (67 loc) ยท 3.92 KB

fmt.md

File metadata and controls

79 lines (67 loc) ยท 3.92 KB

fmt

๊ฐ€์žฅ ์ฒ˜์Œ ์ ‘ํ•˜๋Š” ํŒจํ‚ค์ง€๋กœ, c์–ธ์–ด ํ‘œ์ค€ ์ž…์ถœ๋ ฅ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ stdio ํ—ค๋”์™€ ๋™์ผํ•œ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•จ๐Ÿ“

fmt Index

ํŠนํžˆ ๋‚˜๋Š” append, print/printf/println/Sprint๋ฅผ ์ž์ฃผ ์“ฐ๋Š” ํŽธ์ž„โ—

Append

  • Append(b []byte, a ... any) []byte
    • byte slice์— ๋ณ€์ˆ˜ appendํ•˜๋Š” ํ•จ์ˆ˜
  • Appendf(b []byte, format string, a ...any) []byte
    • ์ง€์ •ํ•œ ํ˜•์‹์— ๋”ฐ๋ผ, byte slice์— ๊ฐ’ appendํ•˜๋Š” ํ•จ์ˆ˜
  • Appendln(b []byte, a ...any) []byte
    • Append ํ•จ์ˆ˜์ฒ˜๋Ÿผ ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ๊ทธ๋‹ค์Œ์— ๊ฐœํ–‰๋ฌธ์ž(\n)๊ฐ€ ๋“ค์–ด๊ฐ

์ถœ๋ ฅ

  • Errorf(format string, a ... any) error
    • error ํฌ๋งทํŒ…ํ•˜๋Š” ํ•จ์ˆ˜
  • Print(a ...any) (n int, err error)
    • ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋กœ, ๋‚ด๋ถ€์ ์œผ๋กœ๋Š” Fprint์„ ์‚ฌ์šฉํ•จ
  • Printf(format string, a ...any) (n int, err error)
    • ์ง€์ •ํ•œ ํ˜•์‹์— ๋”ฐ๋ผ, ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜
  • Println(a ...any) (n int, err error)
    • ๋งˆ์ง€๋ง‰ ๊ฐœํ–‰๋ฌธ์ž(\n)์ด ๋“ค์–ด๊ฐ„ ์ถœ๋ ฅ ํ•จ์ˆ˜
  • Fprint(w io.Writer, a ... any) (n int, err error)
    • F๊ฐ€ ๋ถ™์€ ํ•จ์ˆ˜๋“ค์€ ํŒŒ์ผ(File) ์ถœ๋ ฅ์„ ์˜๋ฏธํ•จ
    • ์ฆ‰, ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ค์–ด์„œ ํŒŒ์ผ์— ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
    • io.Writer ํƒ€์ž…์„ ๋ฐ›์•„ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋กœ, Print๋Š” ํ‘œ์ค€์ถœ๋ ฅ์ธ os.Stdout์„ ๋„˜๊ฒจ ํ„ฐ๋ฏธ๋„์— ๊ธฐ๋กํ•˜๋Š” ์›๋ฆฌ์ž„
  • Fprintf(w io.Writer, format string, a ... any) (n int, err error)
    • Fprint์ฒ˜๋Ÿผ ๋™์ผํ•˜์ง€๋งŒ, ์ง€์ •ํ•œ ํ˜•์‹์— ๋”ฐ๋ผ ํŒŒ์ผ์— ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
  • Fprintln(w io.Writer, a ... any) (n int, err error)
    • Fprint์ฒ˜๋Ÿผ ๋™์ผํ•˜์ง€๋งŒ, ๋งˆ์ง€๋ง‰์— ๊ฐœํ–‰๋ฌธ์ž(\n)๋ฅผ ๋ถ™์—ฌ์„œ ํŒŒ์ผ์— ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜

์ž…๋ ฅ

  • Scan(a ...any) (n int, err error)
    • ์ฝ˜์†”๋กœ ์ž…๋ ฅ ๋ฐ›์•„์„œ, ํŠน์ • ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
  • Scanf(format string, a ...any) (n int, err error)
    • ์ง€์ •ํ•œ ํ˜•์‹์— ๋”ฐ๋ผ, ๊ฐ’์„ ์ž…๋ ฅํ•˜๋Š” ํ•จ์ˆ˜
  • Scanln(a ...any) (n int, err error)
    • ๋งˆ์ง€๋ง‰์— ๊ฐœํ–‰๋ฌธ์ž(\n)๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ์ž…๋ ฅํ•จ์ˆ˜
  • Sprint(a ...any) string
    • ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํ•จ์ˆ˜
  • Sprintf(format string, a ...any) string ์ง€์ •ํ•œ ํ˜•์‹์— ๋”ฐ๋ผ(ํ˜•์‹์ง€์ •ํ•˜์—ฌ), ๋ฌธ์ž์—ด์„ ๋งŒ๋“ฆ
  • Sprintln(a ...any) string
    • ๋ฌธ์ž์—ด ๋งˆ์ง€๋ง‰์— ๊ฐœํ–‰๋ฌธ์ž(\n)๊ฐ€ ๋ถ™์Œ.
  • Fscan(r io.Reader, a ...any) (n int, err error)
    • ํŒŒ์ผ์„ ์ฝ๊ณ , ๊ณต๋ฐฑ์ด๋‚˜ ๊ฐœํ–‰๋ฌธ์ž๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด์—์„œ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜
  • Fscanf(r io.Reader, format string, a ...any) (n int, err error)
    • ํ˜•์‹์„ ์ง€์ •ํ•˜์—ฌ ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜
  • Fscanln(r io.Reader, a ...any) (n int, err error)
    • ํŒŒ์ผ์„ ์ฝ๊ณ , ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด์—์„œ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜
  • Sscan(str string, a ...any) (n int, err error)
    • ๊ณต๋ฐฑ, ๊ฐœํ–‰๋ฌธ์ž๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด์—์„œ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜
  • Sscanf(str string, format string, a ...any) (n int, err error)
    • ๋ฌธ์ž์—ด์—์„œ ํ˜•์‹์„ ์ง€์ •ํ•˜์—ฌ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜
  • Sscanln(str string, a ...any) (n int, err error)
    • ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋œ ๋ฌธ์ž์—ด์—์„œ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜

๊ทธ ์™ธ

  • WARNING : error strings should not end with punction or newlines(ST1005)
    • fmt.Errorf()ํ•จ์ˆ˜๋‚˜, fmt.Sprintf()๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—๋Ÿฌ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒฝ์šฐ์— ๋ฐœ์ƒํ•ด์„œ ์ฐพ์•„๋ด„
    • ์—๋Ÿฌ์ฝ”๋“œ ๋ฉ”์‹œ์ง€ ๋ฌธ๊ตฌ์˜ ์ฒซ๋ฒˆ์งธ ๊ธ€์ž๊ฐ€ ๋Œ€๋ฌธ์ž์ธ ๊ฒฝ์šฐ์™€ ๋งˆ์ง€๋ง‰์— "." ๋งˆ์นจํ‘œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ๋ฐœ์ƒ
    • WARNING์ด๋ฏ€๋กœ ํฌ๋ฆฌํ‹ฐ์ปฌ ํ•˜์ง€ ์•Š์ง€๋งŒ, ์ฐธ๊ณ ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„ ๊ธฐ๋ก๐Ÿ“

์ฐธ๊ณ