1

So I have to parse an XML file for my C++ project in class and I'm using RapidXML. The rapidxml_iterators.hpp file is giving me some troubles. I'm using Dev C++ by the way

At first, I had the following code:

typedef typename xml_node<Ch> value_type;
typedef typename xml_node<Ch> &reference;
typedef typename xml_node<Ch> *pointer;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;

Inside my main.cpp, I did: #include "rapidxml_iterators.hpp" and gave me an expected nested-name specifier error when I tried to compile it. I followed the instructions from compile rapidxml under linux with g++ and changed the code from the top to the following:

typedef xml_node<Ch> value_type;
typedef xml_node<Ch> &reference;
typedef xml_node<Ch> *pointer;
typedef typename std::ptrdiff_t difference_type;
typedef typename std::bidirectional_iterator_tag iterator_category;

Now, it's giving me these errors:

-no class template named ptrdiff_t' instd' -ISO C++ forbids declaration of `difference_type' with no type

If anyone has any ideas on how to fix this code, I'd be forever grateful. Thanks in advance!

Community
  • 1
  • 1
  • The other errors are: `ISO C++ forbids the declaration of difference_type with no type` and `no class template named bidirectional_iterator_tag in std` and the rest of the errors are just repeated instances of these two but with different things such as `iterator_category` – user2137877 Mar 06 '13 at 18:24

1 Answers1

0

You lack the definition of std::ptrdiff_t. So the compiler tells you that you cannot typedef it since it is not defined.

Just include the proper header at the top of your file and you'll be good (with this error only!), that is, add:

#include <cstddef>
Qortex
  • 7,087
  • 3
  • 42
  • 59
  • Hey thanks a lot for your reply! Now I'm not getting the std::ptrdiff_t error anymore but it still gives me these issues: `ISO C++ forbids the declaration of difference_type with no type` and `no class template named bidirectional_iterator_tag in std` and the rest of the errors are just repeated instances of these two – user2137877 Mar 06 '13 at 18:13
  • Ok cool. Then please mark this as an answer so that this issue is closed, and open a new topic with your new problems if you feel like it. – Qortex Mar 06 '13 at 18:21
  • Actually, no it still gives me the `std::ptrdiff_t` error still. Wow – user2137877 Mar 06 '13 at 18:23
  • any other suggestions? I'm clueless. Is it because of Dev C++? – user2137877 Mar 06 '13 at 18:39
  • look for your `cstddef` header on your system and look what's inside. Does it define `std::ptrdiff_t`? Maybe you need to turn a flag on? Post your header on a pastebin and post it as an update to your initial post. – Qortex Mar 06 '13 at 19:10
  • Where would I be able to check the header? – user2137877 Mar 06 '13 at 20:11
  • depends on your system, check for the place of the standard header, or just do a filename search on the header you want. – Qortex Mar 06 '13 at 20:22