-
Notifications
You must be signed in to change notification settings - Fork 3
Home
aelliixx edited this page Mar 20, 2024
·
3 revisions
Welcome to the cpp-inquirer wiki! I hope to provide some usage examples even the most beginner users can follow.
std::string answer = alx::Question{"any key", "What's your name?"}.ask(); // Keys do not matter in this example
Or you can instantiate a Question object and retrieve the answer later.
alx::Question question{"any key", "What's your name?"}.ask();
std::string answer = question.get_answer();
auto inquirer = alx::Inquirer();
inquirer.add_question({ "query", "What do you want to do?" }); // Keys *do* matter when using them with 'alx::Inquirer' class
inquirer.ask();
auto inquirer = alx::Inquirer();
inquirer.add_question({ "query", "What do you want to do?" }).ask();
// Calling inquirer.ask() would not prompt the user with an answered question again. To ask the user again, call 'ask()' like this
inquirer.ask(true);
std::string answer = inquirer.answer("query"); // Where "query" is the key of your question.
std::string name;
alx::Question question{ "query", "What's your name?" };
while (name.empty()) // This is your criteria
name = question.ask(true);