Re: Std Map .. Help

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 04/20/04


Date: Tue, 20 Apr 2004 21:01:17 +0100


<ash> wrote in message news:6hva805ff5l984slf2m9ogsjo8i5c2f7k5@4ax.com...
> Hi,
>
> I'm getting started with STL, and am stuck at creating a map
> container. I checked one of the texts and found a code in there. To
> make it simple, i wrote the following:
>
> #include <iostream.h>

Non-standard header file, use <iostream> (without a .h)

> #include <string.h>

This is a valid header file, but it doesn't declare the std::string class
which is what you are thinking it does, instead it declares the C string
handling routines. Use <string> instead (again without a .h)

> #include <map>
>
> typedef std::map<string,string,std::less<string>> mymap;

std::less is unecessary, but string is wrong, it should be std::string. Try
this

typedef std::map<std::string,std::string> mymap;

>
> int main()
> {
> mymap somemap;
> return 0;
> }
>
>
> This gives me 6 error messages, an a warning. Could anyone point me
> the mistake....i've been to grasp the topic for two days now!

Don't know what book you are reading, doesn't it have any syntactically
valid programs in it?

You need to use the correct header files (no C++ header files have .h in
them)
You need to remember std::
You should forget about std::less (at least for now).

john



Relevant Pages

  • Re: How to Define a global const class variable in MFC?
    ... but in vc++ it seems that we have to both declare and define variables in ... would declare an array of fixed size in C++ escapes me...). ... I can write the whole header files and source files but I thought it will be ... declarations are so we can figure out why the error message, that SPECIFIC error message, ...
    (microsoft.public.vc.mfc)
  • A C++ Whishlist
    ... Now I have come to really like Java Strings. ... a String is a String is a String. ... I believe header files are nothing but a nuisance. ... or declare it to be thrown in the function declaration. ...
    (comp.lang.cpp)
  • Re: Fetch function names & prototypes?
    ... > although in C++ the prototypes are found in the header files included ... > string into the object file symbol table, ... trick would not allow a perfect/accurate type checking. ... arguments have complex data types, ...
    (comp.compilers)
  • Re: Structure of MFC
    ... You declare the variables where they are needed. ... You initialize them at the point where it ... It's just programming. ... put them in header files you create. ...
    (microsoft.public.vc.mfc)
  • Re: [ACPI] [PATCH] Updated patches for PCI IRQ resource deallocation support [2/3]
    ... On Wed, 29 Sep 2004, Kenji Kaneshige wrote: ... > many other header files, so many 'implicit declaration of function xxx' ... > warning message would be appeared. ... acpi_unregister_gsi to declare them as static inline in header files. ...
    (Linux-Kernel)