Commands with arguments
#6

One easy way would be using a stringstream and std::getline. There are also many libraries out there that will do this more efficiently/faster like boost::tokenizer.
PHP код:
#include <sstream>
#include <vector>
/** Will be used to push back params into vector **/
std::string Buffer{};
/** Storage for params. **/
std::vector<std::stringParams{};
/** Construct stringstream with cmdtext. **/
std::stringstream sscmdtext };
/** Loop through stream extracting params. (space delimiter)**/
while ( std::getline(ssBuffer' ') )
{
    
Params.push_backstd::move(Buffer) );
}
/** Get an int **/
// you will need to bounds check before indexing params. Params.size() returns number of params supplied
if (Params.size() == 3)//params[0] is the command name
{
    
/** Cast params. **/
    
int PlayerID stoi(Params[1]);
    
int Level stoi(Params[2]);

Reply


Messages In This Thread
Commands with arguments - by devStyle - 02.07.2016, 20:21
Re: Commands with arguments - by CodeStyle175 - 02.07.2016, 22:05
Re: Commands with arguments - by devStyle - 02.07.2016, 22:16
Re: Commands with arguments - by NewbProgrammer - 03.07.2016, 03:52
Re: Commands with arguments - by devStyle - 03.07.2016, 06:36
Re: Commands with arguments - by iggy1 - 03.07.2016, 11:18

Forum Jump:


Users browsing this thread: 1 Guest(s)