"Go 문자열 포인터를 문자열로 변환"의 두 판 사이의 차이

2번째 줄: 2번째 줄:
;Go 문자열 포인터를 문자열로 변환
;Go 문자열 포인터를 문자열로 변환


{{소스헤더|라이브러리 사용 안함}}
<syntaxhighlight lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main
17번째 줄: 16번째 줄:
</syntaxhighlight>
</syntaxhighlight>


{{소스헤더|k8s.io/utils/ptr 사용}}
<syntaxhighlight lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main

2024년 6월 13일 (목) 13:17 판

1 개요

Go 문자열 포인터를 문자열로 변환
package main

import "fmt"

func main() {
	temp := "Hello, 世界"
	foo := &temp
	bar := *foo
	fmt.Println(foo) // 0xc00010a210
	fmt.Println(bar) // Hello, 世界
}
package main

import (
	"fmt"

	"k8s.io/utils/ptr"
)

func main() {
	foo := ptr.To[string]("Hello, 世界")
	bar := *foo
	fmt.Println(foo) // 0xc00010a210
	fmt.Println(bar) // Hello, 世界
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}