Error when trying to use fstream

This is a discussion on Error when trying to use fstream within the C++ Programming forums, part of the General Programming Boards category; I'm trying to use fstream for some file I/O, but I'm getting the following error: fstream (465) error C2061: syntax ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    61

    Error when trying to use fstream

    I'm trying to use fstream for some file I/O, but I'm getting the following error:

    fstream (465) error C2061: syntax error : identifier '_DebugHeapTag'
    any idea why this is occurring, and how to fix it?

    BTW, Merry Christmas to everyone!

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    Did you Google the error first?

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Yes, I did. I found two different scenarios offered:

    1) I'm using a mixture of old and new I/O headers and functions
    2) I'm redefining the keyword new

    I'm not actually writing a new program, but modding Civilization 4 Beyond the Sword, so while both of these scenarios are actually correct, I can't really go and change them without undoubtedly causing a lot of headaches. So, I'm hoping there's another way around it somehow.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,590
    can you show us what headers you're including?

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Well, I'm modding the SDK for Civ4 BTS, so there are quite a few headers used. I searched for #include <, which should bring up all the headers not included in the SDK itself, and here's what I got:

    CvGameCoreDLL.h(17):#include <windows.h>
    CvGameCoreDLL.h(18):#include <MMSystem.h>
    CvGameCoreDLL.h(21):#include <crtdbg.h>
    CvGameCoreDLL.h(23):#include <vector>
    CvGameCoreDLL.h(24):#include <list>
    CvGameCoreDLL.h(25):#include <tchar.h>
    CvGameCoreDLL.h(26):#include <math.h>
    CvGameCoreDLL.h(27):#include <assert.h>
    CvGameCoreDLL.h(28):#include <map>
    CvGameCoreDLL.h(29):#include <hash_map>
    CvPlot.h(10):#include <bitset>
    CvString.h(6):#include <string>
    CyCity.h(10):#include <string>
    CyMessageControl.h(6):#include <boost/python/list.hpp>
    CyMessageControl.h(7):#include <boost/python/tuple.hpp>
    FDialogTemplate.h(8):#include <windows.h> // This is needed just for the LPCSTR, DWORD, and WORD typedefs
    CvGame.cpp(24):#include <set>
    CvGameCoreDLL.cpp(5):#include <new>
    CvGameCoreUtils.cpp(3):#include <algorithm>
    CvInitCore.cpp(31):#include <shlobj.h>
    CvSelectionGroup.cpp(23):#include <set>
    CvSelectionGroup.cpp(53):#include <fstream> // This is where I'm trying to include fstream
    CvXMLLoadUtilityModTools.cpp(17):#include <string>
    CvXMLLoadUtilitySet.cpp(11):#include <algorithm>
    FAssert.cpp(7):#include <tchar.h>
    FAssert.cpp(8):#include <stdio.h>
    FDialogTemplate.cpp(7):#include <tchar.h>
    As you can see, it's including stdio.h and I'm trying to include fstream. This (according to scenario #1) could be what's causing the problem.

    However, like I said in scenario #2, the keyword new is also redefined here:

    Code:
    #define new new(__FILE__, __LINE__)
    I commented this line out and it allowed me to compile, but I'm pretty sure I need to keep it in there for the game to run properly, so I don't think this is a feasible solution.
    Last edited by LyTning94; 12-25-2011 at 06:20 PM.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2,590
    well you should know that new is a keyword in C++ and you cannot redefine its meaning. you can overload it, because it's an operator, but you cannot use it as a preprocessor macro.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Someone else familiar with the BTS SDK just told me it would be safe to comment out that line, so never mind.
    Last edited by LyTning94; 12-26-2011 at 10:00 AM.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    It seems like they're using Microsoft's debug new which will print out if any memory leaks have occurred when you close the program.
    If it is fine for you to be without it, then commenting it out should be fine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fstream
    By Amyaayaa in forum C++ Programming
    Replies: 2
    Last Post: 03-29-2008, 10:44 PM
  2. fstream error
    By sunoflight77 in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2005, 06:36 AM
  3. About "fstream" in <fstream.h> and <fstream>
    By L.O.K. in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 06:49 PM
  4. some help with fstream
    By Geo-Fry in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2003, 04:45 PM
  5. stl fstream error (yes... file problems again)
    By ygfperson in forum C++ Programming
    Replies: 7
    Last Post: 07-13-2002, 11:47 PM

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