Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML and std::cout  (Read 6984 times)

0 Members and 1 Guest are viewing this topic.

cheesesteak

  • Newbie
  • *
  • Posts: 4
    • View Profile
SFML and std::cout
« on: February 08, 2014, 05:19:08 pm »
Good evening everybody!

I just started reading "SFML Game Development". So far I like both the book and SFML! I have one question, though:

Whenever I program in C++ and something doesn't work, I print the involved values using std::cout. I noticed that this doesn't work with SFML:

if (!this->mTexture.loadFromFile("res/plane.png"))
{
        std::cout << "Texture plane.png couldn't be loaded.";
}

When I intentionally remove plane.png, recompile the program and then run it in terminal mode, I only get to see SMFL's error message, not my string.

Is it generally impossible to use std::cout in combination with SFML? If so, what can be used alternatively?

Thank you!

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML and std::cout
« Reply #1 on: February 08, 2014, 05:45:05 pm »
You need to output std::flush to std::cout to see anything.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML and std::cout
« Reply #2 on: February 08, 2014, 07:16:14 pm »
Or std::endl, which is more commonly used since people usually want to terminate their messages with a line break ;)
Laurent Gomila - SFML developer

cheesesteak

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML and std::cout
« Reply #3 on: February 08, 2014, 07:35:56 pm »
You need to output std::flush to std::cout to see anything.
Thank you very much, that worked!
Or std::endl, which is more commonly used since people usually want to terminate their messages with a line break ;)
Thank you, too. Normally I use std::endl. If I had done so this time, this question would not have been necessary! However, std::endl works because it calls std::flush implicitly. Thanks to both of you!

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: SFML and std::cout
« Reply #4 on: February 09, 2014, 07:17:05 am »
You could also use std::cerr, which, is what this (error reporting) is meant for.

This a case of buffered (cout) vs unbuffered (cerr) output if I'm not mistaken.