I recently started to learn c++, so i'd like to have detailed explanations if you can.
(If i posted in the wrong section, i'm sorry)
Here's the code:
Player.h:
class Player {
public:
Player(std::string, sf::Color);
void Update();
void Draw(sf::RenderWindow*, sf::RenderStates);
private:
...
sf::Text nickname;
sf::Font font;
}
Player.cpp
Player::Player(std::string _nickname, sf::Color color) {
...
nickname.setFont(font);
nickname.setString(_nickname);
nickname.setCharacterSize(12);
nickname.setFillColor(sf::Color(255, 255, 255));
}
void Player::Draw(sf::RenderWindow* window, sf::RenderStates states) {
window->draw(_player, states);
window->draw(nickname, states);
}
Here's the problem:
Main.cpp:
int main() {
...
std::vector<Player> players;
while (window.isOpen()) {
std::string nickname; std::cin >> nickname;
players.push_back(Player::Player(nickname, sf::Color(102, 0, 0)));
window.clear();
window.draw(cursor, states);
for (auto player : players)
player.Draw(&window, states);
window.display();
}
}
When i try to write the nickname on the console, and press ente it gives me the following error:
"Debug assertion failed! Expression: map/set insert iterator out of range".
Thanks in advance.