ok, i'm trying to make something like a command console in games.
it takes a line of input from the user, then breaks the line down into a command and the parameters for it.
i want to use this to do something like:
Code:
if (command=="dothis"){
dothis(parameter[0],parameter[1])
}
here's what i have so far:
Code:
#include <iostream>
#include <sstream>
#include <math.h>
using namespace std;
const string cmd_create="create";
const string cmd_exit="exit";
int main(){
bool run=1;
string input;
int numparameters;
//in-game command line loop
do{
string * parameter;
string * command;
command = new string;
//get input from user
getline(cin,input);
//display what the user entered;
cout << input << endl;
//turn the input into a stream
stringstream inputstream(input);
//take the first part of input and turn it into the command variable
inputstream >> *command;
// set the number of parameters based on the command
if (*command==cmd_create){numparameters=1;}
else {numparameters=1;}
//take the rest of input and turn it into parameters
parameter = new string[numparameters];
for(int count=0;count<numparameters;count++){
inputstream >> parameter[count];}
//display the command the parameters to be used
cout << "Command: " << *command << endl;
for(int count=0;count<numparameters;count++){
cout << "Parameter[" << count << "]: " << parameter[count] << endl;}
//execute commands using parameters
if (*command==cmd_create){
cout << "Creating " << parameter[0] << "..." << endl;
cout << parameter[0] << " created!" << endl;}
if (*command==cmd_exit){
cout << "Exiting program..." << endl;run=0;}
delete command;
delete []parameter;
}while(run==1);
return 0;
}
am i heading in the right direction? or can you see any bad parts to this, because everything compiles and runs fine so far.
and on a wierd note, when i first started writing this post, i ended my sentences with semicolons...