标签:输入输出 please UNC exit 输出 rom finish with code
package main
import (
"fmt"
)
var (
firstName, lastName, s string
i int
f float32
input = "56.12 / 5212 / Go"
format = "%f / %d / %s"
)
func main() {
fmt.Println("Please enter your full name: ")
fmt.Scanln(&firstName, &lastName)
// fmt.Scanf("%s %s", &firstName, &lastName)
fmt.Printf("Hi %s %s!\n", firstName, lastName) // Hi Chris Naegels
fmt.Sscanf(input, format, &f, &i, &s)
fmt.Println("From the string we read: ", f, i, s)
}
package main
import (
"bufio"
"fmt"
"os"
)
var inputReader *bufio.Reader
var input string
var err error
func main() {
inputReader = bufio.NewReader(os.Stdin)
fmt.Println("Please enter some input: ")
input, err = inputReader.ReadString(‘\n‘)
if err == nil {
fmt.Printf("The input was: %s\n", input)
}
}
package main
import (
"bufio"
"os"
"fmt"
)
func main() {
reader := bufio.NewReader(os.Stdin)
//以换行为分割,注意单引号‘‘
str, err := reader.ReadString(‘\n‘)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("输入的是:", str)
}
输入输出:
我日啊
输入的是: 我日啊
Process finished with exit code 0
标签:输入输出 please UNC exit 输出 rom finish with code
原文地址:http://blog.51cto.com/5660061/2347598