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.
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.
Visual Studio:
Build the project, in the build output you should see the include tree. Find the first occurrence of the error, and scan upwards opening each include file (that you wrote) to find which one has the missing curly bracket "}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With