Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Std Map .. Help

Reply
Thread Tools

Std Map .. Help

 
 
ash
Guest
Posts: n/a
 
      04-20-2004
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>
#include <string.h>
#include <map>

typedef std::map<string,string,std::less<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!

Initially i thought i might not be using string properly, so i changed
the code typedef to

typedef std::map<int,int, std::less<int>> mymap;

This give me an error saying :
C:\Documents and Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : error
C2146: syntax error : missing ',' before identifier 'mymap'
C:\Documents and Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : :
error C2065: 'mymap' : undeclared identifier
C:\Documents and Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : error
C2143: syntax error : missing '>' before ';'
C:\Documents and C:\Documents and
Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : warning C4091:
'typedef ' : ignored on left of 'class std::map' when no variable is
declared


Thanks,

Ash
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      04-20-2004

<ash> wrote in message news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      04-20-2004
ash wrote:
> 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>

#include <iostream>
> #include <string.h>

#include <string>

[<string.h> is a C header that contains the prototypes for things like
strcmp(), strcpy(), and the like -- *not* C++ std::string]

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

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

[the space between the enclosing `>'s is necessary]
>
> 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!
>
> Initially i thought i might not be using string properly, so i changed
> the code typedef to
>
> typedef std::map<int,int, std::less<int>> mymap;
>
> This give me an error saying :
> C:\Documents and Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : error
> C2146: syntax error : missing ',' before identifier 'mymap'
> C:\Documents and Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : :
> error C2065: 'mymap' : undeclared identifier
> C:\Documents and Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : error
> C2143: syntax error : missing '>' before ';'
> C:\Documents and C:\Documents and
> Settings\Ash\Desktop\Maps\MuliMap\Main.cpp(4) : warning C4091:
> 'typedef ' : ignored on left of 'class std::map' when no variable is
> declared
>


HTH,
--ag

--
Artie Gold -- Austin, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Problems with std::map.insert() and std::map.find() Thomas J. Gritzan C++ 6 12-22-2008 10:01 AM
Re: Problems with std::map.insert() and std::map.find() James Kanze C++ 0 12-21-2008 10:54 AM
Re: Problems with std::map.insert() and std::map.find() acehreli@gmail.com C++ 1 12-21-2008 06:49 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
std::map<int,std::set<std::string> > Wrong? (Segmentation fault.) Peter Jansson C++ 5 03-17-2005 06:34 AM



Advertisments