Skip to content

Instantly share code, notes, and snippets.

@Kraks
Last active December 15, 2015 21:29
Show Gist options
  • Select an option

  • Save Kraks/5325763 to your computer and use it in GitHub Desktop.

Select an option

Save Kraks/5325763 to your computer and use it in GitHub Desktop.
/* A simple Read–eval–print-loop example
*/
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
string buf;
/*
do {
cout << ">>";
getline(cin, buf);
if (buf.empty()) {
cout << "empty" << endl;
continue;
}
if (!buf.compare("exit")) {
cout << "Now exit" << endl;
exit(0);
}
cout << buf << endl;
} while(1);
*/
while(1) {
cout << ">>";
getline(cin, buf);
if (buf.empty()) {
cout << "empty" << endl;
continue;
}
if (!buf.compare("exit")) {
cout << "Now exit" << endl;
exit(0);
}
cout << buf << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment