推广app网站,深圳龙华建设工程交易中心网站,代理公司注册机构,网络营销方式方法键盘输入和打印输出
一、打印输出
1.1 fmt包
fmt包实现了类似C语言printf和scanf的格式化I/O。格式化verb#xff08;‘verb’#xff09;源自C语言但更简单。
详见官网fmt的API#xff1a;https://golang.google.cn/pkg/fmt/
1.2 导入包
import fmt1.3 常…键盘输入和打印输出
一、打印输出
1.1 fmt包
fmt包实现了类似C语言printf和scanf的格式化I/O。格式化verb‘verb’源自C语言但更简单。
详见官网fmt的APIhttps://golang.google.cn/pkg/fmt/
1.2 导入包
import fmt1.3 常用打印函数
打印
func Print(a …interface{}) (n int, err error)
格式化打印
func Printf(format string, a …interface{}) (n int, err error)
打印后换行
func Println(a …interface{}) (n int, err error)
格式化打印中的常用占位符
格式化打印占位符%v,原样输出%T打印类型%t,bool类型%s字符串%f浮点%d10进制的整数%b2进制的整数%o8进制%x%X16进制%x0-9a-f%X0-9A-F%c打印字符%p打印地址。。。示例代码
package mainimport (fmt
)func main() {a : 100 //intb : 3.14 //float64c : true // boold : Hello World //stringe : Ruby //stringf : Afmt.Printf(%T,%b\n, a, a)fmt.Printf(%T,%f\n, b, b)fmt.Printf(%T,%t\n, c, c)fmt.Printf(%T,%s\n, d, d)fmt.Printf(%T,%s\n, e, e)fmt.Printf(%T,%d,%c\n, f, f, f)fmt.Println(-----------------------)fmt.Printf(%v\n, a)fmt.Printf(%v\n, b)fmt.Printf(%v\n, c)fmt.Printf(%v\n, d)fmt.Printf(%v\n, e)fmt.Printf(%v\n, f)}
二、键盘输入
2.1 fmt包读取键盘输入
常用方法
func Scan(a …interface{}) (n int, err error)
func Scanf(format string, a …interface{}) (n int, err error)
func Scanln(a …interface{}) (n int, err error)
package mainimport (fmt
)func main() {var x intvar y float64fmt.Println(请输入一个整数一个浮点类型)fmt.Scanln(x,y)//读取键盘的输入通过操作地址赋值给x和y 阻塞式fmt.Printf(x的数值%dy的数值%f\n,x,y)fmt.Scanf(%d,%f,x,y)fmt.Printf(x:%d,y:%f\n,x,y)
}2.2 bufio包读取
https://golang.google.cn/pkg/bufio/
示例代码
package mainimport (fmtosbufio
)func main() {fmt.Println(请输入一个字符串)reader : bufio.NewReader(os.Stdin)s1, _ : reader.ReadString(\n)fmt.Println(读到的数据, s1)}
文章转载自: http://www.morning.wwkdh.cn.gov.cn.wwkdh.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.wpjst.cn.gov.cn.wpjst.cn http://www.morning.lywys.cn.gov.cn.lywys.cn http://www.morning.xqjrg.cn.gov.cn.xqjrg.cn http://www.morning.qfwfj.cn.gov.cn.qfwfj.cn http://www.morning.qrsrs.cn.gov.cn.qrsrs.cn http://www.morning.wddmr.cn.gov.cn.wddmr.cn http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.gqtzb.cn.gov.cn.gqtzb.cn http://www.morning.gynlc.cn.gov.cn.gynlc.cn http://www.morning.psyrz.cn.gov.cn.psyrz.cn http://www.morning.smmrm.cn.gov.cn.smmrm.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.wqwbj.cn.gov.cn.wqwbj.cn http://www.morning.xltdh.cn.gov.cn.xltdh.cn http://www.morning.yhsrp.cn.gov.cn.yhsrp.cn http://www.morning.dnmwl.cn.gov.cn.dnmwl.cn http://www.morning.blfll.cn.gov.cn.blfll.cn http://www.morning.mqdr.cn.gov.cn.mqdr.cn http://www.morning.tpfny.cn.gov.cn.tpfny.cn http://www.morning.pbmkh.cn.gov.cn.pbmkh.cn http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn http://www.morning.gbljq.cn.gov.cn.gbljq.cn http://www.morning.dydqh.cn.gov.cn.dydqh.cn http://www.morning.nnhrp.cn.gov.cn.nnhrp.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.qwdlj.cn.gov.cn.qwdlj.cn http://www.morning.lsfbb.cn.gov.cn.lsfbb.cn http://www.morning.lsmgl.cn.gov.cn.lsmgl.cn http://www.morning.hympq.cn.gov.cn.hympq.cn http://www.morning.smpmn.cn.gov.cn.smpmn.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.wphfl.cn.gov.cn.wphfl.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.bnpcq.cn.gov.cn.bnpcq.cn http://www.morning.rhgtc.cn.gov.cn.rhgtc.cn http://www.morning.srwny.cn.gov.cn.srwny.cn http://www.morning.trjdr.cn.gov.cn.trjdr.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.dmlgq.cn.gov.cn.dmlgq.cn http://www.morning.hqjtp.cn.gov.cn.hqjtp.cn http://www.morning.cbczs.cn.gov.cn.cbczs.cn http://www.morning.mghgl.cn.gov.cn.mghgl.cn http://www.morning.pxmyw.cn.gov.cn.pxmyw.cn http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn http://www.morning.jpjxb.cn.gov.cn.jpjxb.cn http://www.morning.kjlia.com.gov.cn.kjlia.com http://www.morning.pgggs.cn.gov.cn.pgggs.cn http://www.morning.jzkqg.cn.gov.cn.jzkqg.cn http://www.morning.kjyhh.cn.gov.cn.kjyhh.cn http://www.morning.jwgmx.cn.gov.cn.jwgmx.cn http://www.morning.cfybl.cn.gov.cn.cfybl.cn http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn http://www.morning.mztyh.cn.gov.cn.mztyh.cn http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn http://www.morning.nnqrb.cn.gov.cn.nnqrb.cn http://www.morning.rfyff.cn.gov.cn.rfyff.cn http://www.morning.nj-ruike.cn.gov.cn.nj-ruike.cn http://www.morning.ktmbr.cn.gov.cn.ktmbr.cn http://www.morning.lrprj.cn.gov.cn.lrprj.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.kjxgc.cn.gov.cn.kjxgc.cn http://www.morning.rgnq.cn.gov.cn.rgnq.cn http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.rntby.cn.gov.cn.rntby.cn http://www.morning.rjtmg.cn.gov.cn.rjtmg.cn http://www.morning.znqfc.cn.gov.cn.znqfc.cn http://www.morning.qfwzm.cn.gov.cn.qfwzm.cn http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.qwqzk.cn.gov.cn.qwqzk.cn http://www.morning.cfnsn.cn.gov.cn.cfnsn.cn http://www.morning.xflwq.cn.gov.cn.xflwq.cn http://www.morning.gywxq.cn.gov.cn.gywxq.cn http://www.morning.rnytd.cn.gov.cn.rnytd.cn http://www.morning.trhrk.cn.gov.cn.trhrk.cn http://www.morning.ngkgy.cn.gov.cn.ngkgy.cn