Let me specify the question. I want to make commands so when user will type eg. go (something)
it will use the go
to specify the function and something
to find what the program should do when variable equals something
. If there is anything unclear, just ask, i know my explanation is strange.
Example:
In program there is a void go(string choice)
function with if
condition including few variables that can be used through choice
string.
User is opening program and typing go
and then string. Program goes to function go
and if string is included in if
loop, then program goes to specific if condition and does what it should eg.:
if(choice == "room")
{
//condition being executed
}
So basically you want a specific function to be executed according to a cmd line input? Easy! Create you main function like this:
int main(int argc, char *argv[])
argc is the argument count and argv is the argument value. Google up on this if you need more info, it's widely used. Use an if statement inside your main function that will call the required function according to the value of argv[]. So when you execute your program you'll execute like
exe_file_name go anything
If you want to call multiple functions dynamically during a single execution you could instead do getline(cin,choice);
if(strcmp(choice, "room")) //condition
我认为应该像
if(strcmp(choice , "room")){//condition being executed}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.