7 Replies - 340 Views - Last Post: 25 January 2013 - 01:24 PM Rate Topic: -----

#1 FatPygmy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-January 13

std::cout... statement being skipped

Posted 25 January 2013 - 02:15 AM

Hello coders, first post and more to come! :)/>

So I'm completely stumped. To start, here is the code:


Graphics::Graphics(void)
{
	window = new sf::RenderWindow(sf::VideoMode(800,600,32), "Map Editor");
	loadImages();
	loadSprites();
	clock.Reset();
	elapsedTime = 0.f;
}

void Graphics::run()
{
	if(clock.GetElapsedTime() >= elapsedTime + 1.f)
	{
		clear();
		draw();
		display();
		std::cout << "test";
		elapsedTime += 1.f;
	}
	std::cout << elapsedTime << std::endl;
}




Quick note: run() is being executed in a never ending loop.

Problem: "test" should be output to the terminal once every second. It is not but the line below it is being executed. I know the line below it is being executed because the cout statement after the if statement is showing that elapsedTime is being incremented once every second. (at least it seems like it is being incremented once a second when watching the terminal) I'm assuming the lines above it are being executed too.

Question: Why isn't "test" output to the terminal?

Is This A Good Question/Topic? 0
  • +

Replies To: std::cout... statement being skipped

#2 FatPygmy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-January 13

Re: std::cout... statement being skipped

Posted 25 January 2013 - 04:22 AM

Update: The function calls clear(), draw(), and display() involved code that i felt wasn't relevant to the problem, but I did try commenting them out and it didn't help.
Was This Post Helpful? 0
  • +
  • -

#3 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: std::cout... statement being skipped

Posted 25 January 2013 - 04:31 AM

Well, can you please tell me the header files that you have used for the program?

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#4 FatPygmy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-January 13

Re: std::cout... statement being skipped

Posted 25 January 2013 - 04:38 AM

these are all the header files included in the compiled classes:

"Manager.h"
"Graphics.h"
"Tile.h" < an empty header file.
<iostream>
<SFML/Graphics.hpp>
<SFML/System.hpp>


if you just wanted to know which header files were included by that file specifically then:

"Graphics.h"
<iostream>
Was This Post Helpful? 0
  • +
  • -

#5 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: std::cout... statement being skipped

Posted 25 January 2013 - 04:48 AM

Ok...have you used using namespace std ?

If not, then try adding it and see if it solves the problem.

regards,
Raghav

This post has been edited by raghav.naganathan: 25 January 2013 - 04:49 AM

Was This Post Helpful? 1
  • +
  • -

#6 FatPygmy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-January 13

Re: std::cout... statement being skipped

Posted 25 January 2013 - 04:52 AM

using namespace std; worked. I don't understand why though. I was using 2 namespaces in the code, could that be part of the issue? std:: for cout and sf:: for SFML stuff.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3568
  • View blog
  • Posts: 11,086
  • Joined: 05-May 12

Re: std::cout... statement being skipped

Posted 25 January 2013 - 05:52 AM

If you are building your program on Windows, and you are compiling the program as a Windows program rather than a console program, then Windows by default will not hook up the standard console. Since the C runtime library writes to the standard console, you aren't getting any output.

If you are building your program on *nix, I'm sorry I don't have enough expertise to help you. Hopefully somebody else does.

Edit after: Ah it seems like your problem has been solved. Congratulations! It is strange though that adding using namespace std; would fix things when the std::cout was already namespace qualified.

This post has been edited by Skydiver: 25 January 2013 - 05:56 AM

Was This Post Helpful? 0
  • +
  • -

#8 FatPygmy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-January 13

Re: std::cout... statement being skipped

Posted 25 January 2013 - 01:24 PM

Yes, its so strange! So to recap, adding using namespace std solved the problem, but this doesn't make a whole lot of sense because std::cout << elapsedTime worked just fine outside the if statement, but inside the if statement, std::cout << "test" won't print anything.

However, if i remove the line that increments elapsedTime, "test" will print. Isn't that weird!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1