A very weird problem

This is a discussion on A very weird problem within the C++ Programming forums, part of the General Programming Boards category; While looking through my game code, I decided I wanted to add high score functionality, but when I put in ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    A very weird problem

    While looking through my game code, I decided I wanted to add high score functionality, but when I put in
    Code:
    #include <fstream>
    I get many errors that disappear when I get rid of the previous line of code. here a 3 of the errors.

    Code:
    C:\MinGW\include\c++\3.4.5\bits\allocator.h|80|error: expected template-name before '<' token|
    
    C:\MinGW\include\c++\3.4.5\bits\allocator.h|80|error: expected '{' before '<' token|
    
    C:\MinGW\include\c++\3.4.5\bits\allocator.h|80|error: expected unqualified-id before '<' token|
    Thanks in advance.

  2. #2
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    I'd ask you why you're using that old GCC/MinGW version, but I think I know why. You're using Dev-C++, right? What compiler switches are you using?
    Also, did you have this problem when using fstream before? Does it behave the same when you include it with empty main function?
    Last edited by Xupicor; 09-21-2010 at 09:38 PM.

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Do you have anything before or after that include?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Other files I've included are windows.h and time.h, I also have libwinmm.a libmsimg32.a linked

  5. #5
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Post MORE code.
    You might have a missing '}' or sth?

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Quote Originally Posted by kmdv View Post
    Post MORE code.
    You might have a missing '}' or sth?
    This is the function were fstream is needed, and I'm not sure if this will work yet because I haven't got to compile it

    Code:
    void GameCycle()
    {
        if(g_bGameEnd)
        {
            ifstream isHighScore("High.score");
            ofstream osHighScore("High.score");
            LPSTR szHighScore;
            int iHighScore;
            isHighScore>> iHighScore;
            iHighScore = (int)szHighScore;
            if(isHighScore == NULL)
                osHighScore<< 0;
            else 
            {
                if(g_iScore > iHighScore)
                  osHighScore<< iHighScore;
            }
        }
        if(!g_bGameEnd){
        if(g_bFocus){
        g_pDuck1->UpdateKillZone();
        g_pDuck2->UpdateKillZone();
        g_pBackDuck1->UpdateKillZone();
        g_pBackDuck2->UpdateKillZone();
        InvalidateRect(g_pGame->GetWindow(), NULL, FALSE);
        if(g_bRegularMode){
        if(g_pDuck1->m_iDuckX >= 475 || g_pDuck2->m_iDuckX >= 475)
            g_iTries++;
        if(g_pDuck1->m_iDuckX >= 475 && g_pDuck2->m_iDuckX >= 475)
            g_iTries += 1;
        if(g_pBackDuck1->GetRect().right <= 6 || g_pBackDuck2->GetRect().right <= 6)
            g_iTries++;
        if(g_pBackDuck1->GetRect().right <= 6 && g_pBackDuck2->GetRect().right <= 6)
            g_iTries += 1;
        if(g_iTries >= 5){
            GameOver();
        }
        }
        if(g_bTimedMode)
        {
            clock_t ctTimer;
    
            ctTimer = 30 * CLOCKS_PER_SEC;
    
            if(clock() >= ctTimer)
                GameOver();
        }
        }
        }
    }

  7. #7
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    It would be nice if you'd answer my questions from my post (just below the first post of this topic?)
    If you get the same errors at empty example code like this:
    Code:
    #include <fstream>
    
    int main() {
        return 0;
    }
    Then you may have broken library files. If so, why not upgrade to MinGW/GCC 4.5.1?

  8. #8
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Quote Originally Posted by Xupicor View Post
    It would be nice if you'd answer my questions from my post (just below the first post of this topic?)
    If you get the same errors at empty example code like this:
    Code:
    #include <fstream>
    
    int main() {
        return 0;
    }
    Then you may have broken library files. If so, why not upgrade to MinGW/GCC 4.5.1?
    That compiled fine for me. He probably has broken library files, I would try re-installing MinGW.

  9. #9
    Registered User
    Join Date
    Jul 2010
    Location
    Oklahoma
    Posts
    107
    bijan311,

    Please remind the compiler that you are using the standard name space. Otherwise the declarations are considered erroneous. I'm rather confident that will resolve the issues with the missing declarations from the compiler.

    Best Regards,

    New Ink -- Henry
    Kept the text books....
    Went interdisciplinary after college....
    Still looking for a real job since 2005....

    During the interim, I may be reached at ELance, vWorker, FreeLancer, oDesk and WyzAnt.

  10. #10
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Thanks you guys, I just reinstalled MinGW and it worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Problem With Pointer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:50 PM
  2. Weird problem on '02 3.4L V6 auto
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-11-2006, 11:05 PM
  3. Really Weird itoa Problem
    By Grantyt3 in forum C++ Programming
    Replies: 8
    Last Post: 12-19-2005, 11:44 PM
  4. Replies: 6
    Last Post: 05-12-2005, 03:39 AM
  5. Weird class problem!
    By aker_y3k in forum C++ Programming
    Replies: 2
    Last Post: 09-25-2002, 06:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21