03.07.2016, 11:18
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::string> Params{};
/** Construct stringstream with cmdtext. **/
std::stringstream ss{ cmdtext };
/** Loop through stream extracting params. (space delimiter)**/
while ( std::getline(ss, Buffer, ' ') )
{
Params.push_back( std::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]);
}

