I have a question about the map-question JoBe asked at the start of this post. I'm also trying to build a program using <map>, but when i compile i get error that point to code inside the MAP-file.

I saw your post here, and i tried your small program, but even then i get 2 errors inside the MAP-file, and also those warnings you asked about.
I don't know why i get those errors.
JoBe's code was:

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    typedef map<string, int, less<string> > maptype;
    maptype M;

    M["Jan"]   = 1234;
    M["Piet"]  = 9999;
    M["Piet"]  = 3456;
    M["Klaas"] = 5678;

    for(maptype::iterator i = M.begin(); i != M.end(); ++i)
        cout<< (*i).first <<" "<< (*i).second <<endl;

    cout<<"Press any key to continue!\n";
    cin.get();

    return 0;
}

When i make a new project (win32 console app) and i compile it, i get these 2 errors:

c:\program files\microsoft visual studio\vc98\include\map(16) : error C2143: syntax error : missing ';' before 'namespace'
c:\program files\microsoft visual studio\vc98\include\map(16) : error C2501: 'B' : missing storage-class or type specifiers

Anyone any idea why this happens?

TIA

Dani AI

Generated

Short, practical diagnosis and a focused checklist.

This kind of compiler error coming from inside the vendor STL almost never means the STL itself is broken. It usually means the preprocessor or compiler mode produced malformed text before the header was parsed — common causes are: the file being compiled as plain C instead of C++, a precompiled-header mismatch, a stray project macro that collides with symbols in the header, or a local/corrupt header shadowing the system header. Follow the steps below in order; they are low-effort and find the root cause most of the time. Build/rebuild (as suggested) is fine as a first try, and make sure the source really compiles as C++ (as pointed out). (jeffpar.github.io)

Troubleshooting checklist (do these in order)

  1. Confirm compile-as-C++: make sure the file has a C++ extension (.cpp/.cxx) or force C++ with the compiler option (/TP). (jeffpar.github.io)
  2. Precompiled headers: if the project uses PCH (VC’s stdafx.h pattern), include that header first in every source that uses it — or turn PCH off for the file while debugging. Mismatched PCH settings commonly produce errors inside system headers. (stackoverflow.com)
  3. Check for stray macros / project defines: search the project for any single-letter or suspicious #define (and the Project → Preprocessor Definitions). Temporarily placing an #undef for a suspect name before includes can prove a macro collision quickly. (stackoverflow.com)
  4. Confirm which header is actually included: enable the compiler’s include-trace (Show Includes /showIncludes) to see the exact include tree — a local file named like a standard header can silently shadow the real one. (stackoverflow.com)
  5. Inspect preprocessed output: generate the preprocessor output (cl /P or cl /E) and inspect the lines around the error to see what text the compiler actually saw. That usually points exactly to the broken token. Example CLI checks:
    
    cl /showIncludes /P myfile.cpp
    cl /E myfile.cpp > preprocessed.i
    ``` ([stackoverflow.com](https://stackoverflow.com/questions/8978997/how-can-i-see-the-output-of-the-visual-c-preprocessor?utm_source=openai))

If none of the above helps, verify the VC include folder hasn’t been corrupted or replaced (restore or reinstall Service Pack for VC6 if you must), or try the same small test with a modern compiler — many VC6 quirks are fixed in later toolchains. (mcpmag.com)

Summary: rebuild is fine as step one, but the fastest fix is usually (a) ensure the file is compiled as C++, (b) fix PCH usage, and (c) remove/undef any stray macro or local header that’s colliding with the standard headers.

Recommended Answers

All 4 Replies

The code is fine and should work. Try rebuilding solution.

The code is fine and should work. Try rebuilding solution.

i rebuiled it a couple of times, but i still got the errors.
i believe you guys when you say it works, but i don't get why i get these errors. Maybe a fault in my Options or something? i don't know :sad:

Maybe there's a problem with your compiler/IDE installation or with the header files.

Also, make sure your code is being compiled as C++ and not C

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.