Last active
January 2, 2024 04:55
-
-
Save kristopherjohnson/b31bb38cf6485b83f654 to your computer and use it in GitHub Desktop.
Simple example of using the readline library from C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXXFLAGS=-I/usr/local/include --std=c++11 | |
LDFLAGS=-L/usr/local/lib -lreadline | |
rltest: rltest.cpp | |
clean: | |
- /bin/rm rltest | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple test of readline | |
#include <iostream> | |
#include "readline/readline.h" | |
#include "readline/history.h" | |
using namespace std; | |
int main(int argc, char** argv) | |
{ | |
const char *line; | |
while ((line = readline("? ")) != nullptr) { | |
cout << "[" << line << "]" << endl; | |
if (*line) add_history(line); | |
free(line); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is very helpful, thanks for this example!