Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 views
in Technique[技术] by (71.8m points)

go - VSCode runs in debug console for some reason

For some reason, VSCode exclusively runs in the debug console, regardless of if I run with/without debugging. As such, it won't recognise user input, and that's a relatively big problem. It's probably an easy fix, but hoping someone can give me solid advice on how to fix it. I'll stick the actual code I'm running underneath:

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func add(one int, two int) int {
    var three = one + two

    return three
}

func main() {
    var s []int

    one := 0
    two := 1
    input1 := bufio.NewScanner(os.Stdin)
    fmt.Println("How many places of the Fibbonaci sequence? ")
    input1.Scan()
    numplac := input1.Text()
    places, err := strconv.Atoi(numplac)
    _ = err

    for i := 0; i < places; {
        s = append(s, one)
        i++
        if i < places {
            s = append(s, two)
            i++
            one = add(one, two)
            two = add(one, two)
        } else {
            fmt.Printf("Finished at: %d 
", places)
        }
    }
    fmt.Println("Fibbonaci to", places, "places:")
    fmt.Println(s)
    for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
        s[i], s[j] = s[j], s[i]
    }
    fmt.Println("Fibbonaci to", places, "places, reversed:")
    fmt.Println(s)
}

Cheers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Currently go support in visual studio code doesn't work console option (so you can use "console": integratedTerminal) (see reference). You can see a warning about it if you added.

Your options:

  1. Provide input via args, env or envFile (see reference).
  2. Use something like code runner extension, but without debugging.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...