zoukankan      html  css  js  c++  java
  • readline库的使用

    接口十分简单,readline和addhistory:


    #include <stdlib.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <readline/readline.h>
    #include <readline/history.h>


    int main()
    {
        char* input, shell_prompt[100];


        // Configure readline to auto-complete paths when the tab key is hit.
        rl_bind_key(' ', rl_complete);


        for(;;) {
            // Create prompt string from user name and current working directory.
            snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));


            // Display prompt and read input (n.b. input must be freed after use)...
            input = readline(shell_prompt);


            // Check for EOF.
            if (!input)
                break;


            // Add input to history.
            add_history(input);


            // Do stuff...


            // Free input.
            free(input);
        }
    }


    g++ TestReadLine.cc -lreadline就能够了。

  • 相关阅读:
    币值转换
    第八周作业
    第七周作业
    第五周编程总结
    第四周编程总结
    第三周编程总结
    7-1 查找整数
    7-2 求最大值及其下标
    秋季学习总结
    对我影响最大的三个老师
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4501714.html
Copyright © 2011-2022 走看看