Std Map .. Help

A

ash

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
 
J

John Harrison

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 said:
#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 said:
#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 said:
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
 
A

Artie Gold

ash said:
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 said:
#include <string.h>
#include <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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top