栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

与getchar类似的功能

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

与getchar类似的功能

C的

getchar()
示例:

#include <stdio.h>void main(){    char ch;    ch = getchar();    printf("Input Char Is :%c",ch);}

等效:

package mainimport (    "bufio"    "fmt"    "os")func main() {    reader := bufio.NewReader(os.Stdin)    input, _ := reader.ReadString('n')    fmt.Printf("Input Char Is : %v", string([]byte(input)[0]))    // fmt.Printf("You entered: %v", []byte(input))}

最后的注释行仅显示当您按下

tab
第一个元素时,是U + 0009(’CHARACTER TABULATION’)。

但是,由于您的需要(检测选项卡),C

getchar()
并不适合,因为它需要用户按Enter键。您需要的是@miku提到的ncurses的getch()/ readline /
jLine之类的东西。有了这些,您实际上可以等待一次击键。

因此,您有多种选择:

  1. 使用

    ncurses
    /
    readline
    绑定,例如https://pre.google.com/p/goncurses/或类似的https://github.com/nsf/termbox

  2. 自己滚动,请参阅http://play.golang.org/p/plwBIIYiqG作为起点

  3. 用于

    os.Exec
    运行stty或jLine。

参考:

https://groups.google.com/forum/?fromgroups=#!topic/golang-
nuts/zhBE5MH4n-Q

https://groups.google.com/forum/?fromgroups=#!topic/golang-
nuts/S9AO_kHktiY

https://groups.google.com/forum/?fromgroups=#!topic/golang-
nuts/icMfYF8wJCk



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/452343.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号