SFML community forums

Help => General => Topic started by: Justbod on February 08, 2019, 03:12:25 pm

Title: Problem with y out put in console
Post by: Justbod on February 08, 2019, 03:12:25 pm
Hi! If have a really weird problem
The y output is not a number but is :

Jeleki
eleki
leki
eki
ki
i










:AM:am:PM:pm
AM:am:PM:pm

Jeleki is the title of the window.

void display_game(sf::RenderWindow& window, float interpolation)
{
        window.clear();

        for (int x = 0; x < 50; x++) {
                for (int y = 0; y < 50; y++) {
                        //Check if tile should be drawn
                        if (mapdata[x][y] == 1) {
                                sf::Texture tile;
                                if (!tile.loadFromFile("floor_tile_1.png"))
                                {
                                        std::cout << "Error could not load floor tile!";
                                }
                                sf::Sprite tilesprite;
                                tilesprite.setTexture(tile);
                                //int px = x * 40 + 1;
                                //int py = y * 20 + 1;
                                int px = (x - y) * 20;
                                int py = (y - x) * 10;
                                tilesprite.setPosition(px + 500, py + 300);
                                window.draw(tilesprite);
                                //std::cout << "x:" + x << std::endl;
                                std::cout << "y:" + y << std::endl;
                        }
                }
        }

        window.display();
}

If anyone has a clue what is causing this please let me know.
Title: Re: Problem with y out put in console
Post by: Laurent on February 08, 2019, 04:36:41 pm
Quote
std::cout << "y:" + y << std::endl
"y:" + y points to memory address of literal string "y", plus an offset of y. It is of course invalid and causes undefined behaviour.

What you meant is
std::cout << "y: " << y << std::endl