Archived

This topic is now archived and is closed to further replies.

Recommended Posts

I'm looking for 15 minutes to this piece of code, and I really can't figure out why the fuck it does not print anything. I probably am too tired, or I don't know... Any ideas?
    

#include <iostream>

#include <conio.h>

using namespace std;

class test
{
public:
	int i;
	test(){cout<<"ctor"<<endl;};
	~test(){cout<<"dtor"<<endl;};
};

int main(int argc, char *argv[ ], char *envp[ ] )
{
	test *t1 = new test();
	test *t2 = new test();
	cout<<"In the middle"<<endl;
	delete t1;
	delete t2;
	while(!kbhit());
	return 0;
}
    
Forever trusting who we are And nothing else matters - Metallica [edited by - Gabriel Fleseriu on May 3, 2002 6:12:53 PM]

Share this post


Link to post
Share on other sites
Errr..to all:

Yes, it compiles (c'mon, man!)
"new test;" instead of "new test();" gets me nothing.

VC++6.0SP5, W2k, STLPort.

[edit]got it (halfways): if I run from the ide (both F5 or Ctrl+F5) it doesn't work. If I run the exe, it works. God knows why

[edited by - Gabriel Fleseriu on May 3, 2002 6:28:18 PM]

Share this post


Link to post
Share on other sites
Rickmeister    182
Ok.. Just had to ask
It works ok for me too. Both VC++6.0 Sp5 and GCC 2.95.2, so I don''t know what could be wrong with it.. Just did some handy cut & paste job, and it compiled straight out of the (source)box..

Share this post


Link to post
Share on other sites
quote:
Original post by Rickmeister
Ok.. Just had to ask
It works ok for me too. Both VC++6.0 Sp5 and GCC 2.95.2, so I don''t know what could be wrong with it.. Just did some handy cut & paste job, and it compiled straight out of the (source)box..


That is (was... see the edit in the other post) my problem. If I cannot get that running, I probably have to kill myself !!!!!!!

Share this post


Link to post
Share on other sites
Rickmeister    182
quote:
Original post by Gabriel Fleseriu
If I cannot get that running, I probably have to kill myself !!!!!!!


Maybe try reinstalling VC before you try a more permanent solution??

[edited by - Rickmeister on May 3, 2002 7:00:12 PM]

Share this post


Link to post
Share on other sites
SoakinKittens    122
If you are useing MSVC, you might try creating a new project. If the project is a Win32 app or a dialog app, i don''t think they can print from COUT. You should make it a win32 console? app. don''t have my compiler in front of me.

Share this post


Link to post
Share on other sites
petewood    819
maybe it''s closing the dos window before you''ve seen it.

i know you''re checking for a key press but try it by clicking the icon instead of pressing f5.

maybe a rebuild all

Share this post


Link to post
Share on other sites
quote:
Original post by SoakinKittens
If you are useing MSVC, you might try creating a new project. If the project is a Win32 app or a dialog app, i don''t think they can print from COUT. You should make it a win32 console? app. don''t have my compiler in front of me.


Thanks for the advice, I''ll try w/ a new project, just to have a diagnosis. And, no, I''m not trying to use cout w/o a console (in fact it''s a console app - i said in one post that it runs when the .exe is started directly)

quote:
Original post by petewood
maybe it''s closing the dos window before you''ve seen it.

i know you''re checking for a key press but try it by clicking the icon instead of pressing f5.

maybe a rebuild all


no, the console stys.
imagine that i tried everything i could think of before posting here

Share this post


Link to post
Share on other sites
IndirectX    122
Dunno if you still need this, but I just noticed this thread.

The thing is that cout is buffered while kbhit isn''t. So everything will be printed after you get your kbhit. Use

  
cout << flush;

before kbhit test and you should see your output.

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
The endl should flush it though

Exit VC, delete the debug/release directories, and do a full-rebuild.


Thx, I already did that and it did not work. It seems that VC++ gets confuzed if you remove the include of stdafx.h (wich I did ), the project uses precompiled headers, and you don't do a "hard" rebuild all (i.e delete all temp files - i.e. .ncb and so on).
Just to draw a basline to this thread: I played around with the project, deleted files, eventually made a new project, pasted the code (this one didn't work from scratch, either), deleted some temp files and the deb/rel dirs once more, and it suddenly worked. I cannot say wich of the things I've done fixed it...
It's simply annoying when you want to test something (actually I wanted to test something completely different) and such simple code like that doesn't work

Thx again for all replies.

[edit] typo



Forever trusting who we are
And nothing else matters
- Metallica


[edited by - Gabriel Fleseriu on May 10, 2002 4:05:25 AM]

Share this post


Link to post
Share on other sites