wlibaers
Legacy Member
Nog een optie, als je er iets tegen hebt om de naam twee keer te moeten intikken 
Werkt uiteraard alleen als functie en commando identiek zijn, en bekend tijdens de compilatie.

Code:
#include <string>
#include <map>
#include <iostream>
void f1()
{
std::cout << "\nf1 gekozen\n\n";
}
void f2()
{
std::cout << "\nf2 gekozen\n\n";
}
bool bstop = false;
void stop()
{
bstop = true;
}
#define NIEUWCOMMANDO(x) commandolijst[#x] = x
int main()
{
std::string commando;
std::map<std::string, void (*)()> commandolijst;
NIEUWCOMMANDO(f1);
NIEUWCOMMANDO(f2);
NIEUWCOMMANDO(stop);
while (bstop == false)
{
std::cout << "geef commando\n";
std::cin >> commando;
if (commandolijst.find(commando)!=commandolijst.end())
commandolijst[commando]();
else
std::cout << "\nOngeldig!\n\n";
}
return 0;
}
Werkt uiteraard alleen als functie en commando identiek zijn, en bekend tijdens de compilatie.
