본문 바로가기

Code/go & python & java

vscode terminal with go scanf()

vscode ternimal

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)
		fmt.Printf("%d\n", a+b)
		t = t - 1
		if t == 0 {
			return
		}
	}
}

결과가 이상함.

git bash

git bash 에서는 제대로 나옴

 

 

해결방법

그냥 scanf 뒤에 newline (\n) 다 넣어주면 됨.