Thread: Don't know if I'm losing my mind...

  1. #1
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    Don't know if I'm losing my mind...

    but I've never run into this before. Why would this code see the while loop before the cout statement. Compile it, use escape to exit the loop and then the cout statement will appear even though it comes before the while loop in the code. Using the standard namespace fixes the problem. Why?

    Code:
    #include <conio.h>
    #include <iostream.h>
    
    
    int main()
    {
    	bool done = false;
    	cout << "What's going on here?!\n";
    	while(!done)
    	{
    	   if(getch() == 27)
    		   done = true;
    	}
    return 1;
    }
    "The mind, like a parachute, only functions when open."

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Maybe your compiler looks at the bool declaration as some sort of function?

    Thats just wierd...

    What is C++?

  3. #3
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    It's not the bool, it's the while statement. I don't remember encountering this weirdness before I installed VS6 service pack 5 yesterday. Did you try compiling it?
    "The mind, like a parachute, only functions when open."

  4. #4
    Unregistered
    Guest
    interesting... Borland C++ works as expected.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    try return 0;?
    What is C++?

  6. #6
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    I wish...
    "The mind, like a parachute, only functions when open."

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    i just dont know...

    I cant figure this one out.
    A job for Prelude maybe? LOL

    Oh is there a purpose to this code?
    What is C++?

  8. #8
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    No purpose, just my sanity.
    "The mind, like a parachute, only functions when open."

  9. #9
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Sanity..

    Something that you lose often when programming. Especially with new compilers. I switched to Borland from Dev C++ and oh boy...

    I thought I was goin crazy cause i couldnt get his code to work:

    Code:
    #include <iostrem.h>
    
    int main()
    {
         cout<<"Hello";
    
         cin.get();
         return 0;
    }
    took me almost 2 hours to figure out my problems
    What is C++?

  10. #10
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Lightbulb

    Maybe the compiler you use has some bugs

    The Turbo C 2.0 compiler does some weird things too with certain switch statements.
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  11. #11
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    I'm sure it does... I think this began when I installed the latest service pack. But I'm not certified to make this judgement. If anyone with VS6 and service pack 5 would compile this code I would appreciate it.
    "The mind, like a parachute, only functions when open."

  12. #12
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Question

    What's VS6 and its service pack?
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  13. #13
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I wouldnt let this little bug drive you insane...

    Could you imagine all the time youd lose focusing on this?

    Go make a program sheesh... or btter yet go to my posts and help me!

    What is C++?

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I have VC++ 6.0 SP5. I run into the same problem you explained. Switch this line to fix it.

    cout << "What's going on here?!\n";

    to this...

    cout <<"What's going on here?!" << endl;
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  15. #15
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    DOH!!!

    Oh so simple...
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 11:50 PM
  2. Whats on your mind?
    By Fountain in forum A Brief History of Cprogramming.com
    Replies: 59
    Last Post: 09-27-2003, 02:10 AM
  3. Windows Mind Control
    By Fountain in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-05-2002, 01:59 PM
  4. friday night coding with mind numbing music
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-13-2002, 05:17 PM
  5. Lost source... losing mind...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-27-2001, 12:31 AM