1 package main
2
3 import (
4 "bufio"
5 "fmt"
6 "os"
7 )
8
9 func main() {
10 /*
11 输入和输出:
12 fmt包:输入,输出
13
14 输出:
15 Print() //打印
16 Printf() //格式化打印
17 Println() //打印之后换行
18
19 格式化打印占位符:
20 %v,原样输出
21 %T,打印类型
22 %t,bool类型
23 %s,字符串
24 %f,浮点
25 %d,10进制的整数
26 %b,2进制的整数
27 %o,8进制
28 %x,%X,16进制
29 %x:0-9,a-f
30 %X:0-9,A-F
31 %c,打印字符
32 %p,打印地址
33 。。。
34
35 输入:
36 Scanln()
37 Scanln is similar to Scan, but stops scanning at a newline and after the final item there must be a newline or EOF.
38 Scanf()
39
40 bufio包
41
42 */
43
44 // a := 100 // int
45 // b := 3.14 // float64
46 // c := true // bool
47 // d := "Hello World" // string
48 // e := `Ruby` // string
49 // f := 'A'
50 // fmt.Printf("%T,%b\n", a, a) // int,1100100
51 // fmt.Printf("%T,%f\n", b, b) // float64,3.140000
52 // fmt.Printf("%T,%t\n", c, c) // bool,true
53 // fmt.Printf("%T,%s\n", d, d) // string,Hello World
54 // fmt.Printf("%T,%s\n", e, e) // string,Ruby
55 // fmt.Printf("%T,%d,%c\n", f, f, f) // int32,65,A
56
57 // var x int
58 // var y float64
59 // fmt.Println("请输入一个整数,一个浮点类型:")
60 // fmt.Scanln(&x, &y) // 读取键盘的输入,通过操作地址,赋值给x和y 阻塞式
61 // fmt.Printf("x的数值:%d,y的数值:%f\n", x, y) // x的数值:10,y的数值:10.000000
62
63 // fmt.Scanf("%d,%f", &x, &y)
64 // fmt.Printf("x:%d,y:%f\n", x, y) // x:1,y:10.000000 y 没有被改变
65
66 fmt.Println("请输入一个字符串:")
67 reader := bufio.NewReader(os.Stdin)
68 s1, _ := reader.ReadString('\n')
69 fmt.Println("读到的数据:", s1) // 读到的数据: aaa bbb ccc ddd
70
71 }