Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Last active January 2, 2024 04:55
Show Gist options
  • Save kristopherjohnson/b31bb38cf6485b83f654 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/b31bb38cf6485b83f654 to your computer and use it in GitHub Desktop.
Simple example of using the readline library from C++
CXXFLAGS=-I/usr/local/include --std=c++11
LDFLAGS=-L/usr/local/lib -lreadline
rltest: rltest.cpp
clean:
- /bin/rm rltest
// 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;
}
@RaidenTaisha
Copy link

This code is very helpful, thanks for this example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment