Errors within standard header files

c, c++, header, syntax

Solution

In C/C++, the preprocessor runs before the source code is actually parsed, and `#include`s basically just splice together different files. One consequence of this is that C/C++ are perfectly happy with having a `{` in one file match a `}` in another (included) file. Of course, no one ever does this (or if they do, they should be shot), but because the C/C++ preprocessor is so simple-minded, it's technically allowed.

One consequence of this is that a syntax error in one of your own files can end up looking like a syntax error in some other file. I most often encounter this myself when I forget to put a `;` after a class definition. But mismatched `{}`s can (as you discovered) have the same effect.

So if you ever see an error in some included file that you think probably shouldn't be there (eg a standard library), then the first place to look is whatever file was included just before that file. Sometimes rearranging your `#include` statements can help narrow down the source of the error as well.

Problem

I'm currently getting the following errors: c:\program files\microsoft visual studio\vc98\include\iomanip(15) : error C2059: >syntax error : 'namespace' c:\program files\microsoft visual studio\vc98\include\iomanip(15) : error C2334: >unexpected token(s) preceding '{'; skipping apparent function body c:\program files\microsoft visual studio\vc98\include\math.h(36) : error C2059: syntax >error : 'string' c:\program files\microsoft visual studio\vc98\include\math.h(36) : error C2334: unexpected >token(s) preceding '{'; skipping apparent function body As they are all in the standard library header files, and therefore read only, I don't know how to fix it! Any help would be great.

Original source