I am writing some hobby code today for fun, and while I did some stuff I came along something interesting that I would like to do in a way that sounds and looks nice/great/cool.
The idea is basically that you have a string in C++ and you pass it to a stringstream (to construct the ss).
Then, the expected format is <int or string> <string>
, and you would get the correct output according to the user input like:
bool ExecuteSendPrivateMessage(int sender, std::string params)
{
std::stringstream sparams(params);
int_or_string receiverid;
std::string message;
sparams >> receiverid >> message;
if (sparams.fail())
{
std::cout << "usage: /send_message_to <userid/username> <message>" << std::endl;
return true;
}
if (int_or_string.HasString())
{
receiverid = GetUseridFromUsername(int_or_string.GetString());
}
SendMessage(receiverid.GetInt(), message);
return true;
}
Is this possible in C++? Or with C++ in combination with Boost?
Assuming no user has a name with only numerical characters?