Wie würde ich machen, so dass der letzte Spieler Name ein ,
haben nicht so ist es:Wie kann ich die letzte Iteration in einer C++ while-Schleife erkennen?
Player online:
Jim, John, Tony
und nicht
Player online:
Jim, John, Tony,
Mein Code ist:
bool Commands::whoIsOnline(Creature* c, const std::string &cmd, const std::string ¶m)
{
Player* player = dynamic_cast<Player*>(c);
if (player)
{
player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Players online: ");
AutoList<Player>::listiterator iter = Player::listPlayer.list.begin();
std::string info;
int count = 0;
while (iter != Player::listPlayer.list.end())
{
info += (*iter).second->getName() + ", ";
++iter;
++count;
if (count % 10 == 0)
{
player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, info.c_str());
info.clear();
}
}
if (!info.empty())
player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, info.c_str());
}
return true;
}
letzte Iteration zu erkennen, prüft Looping die Schleifenbedingung. –