I think you misunderstood me on the "using namespace std;"
if you use it, you have to omit the std:: in front of the types you use that come from the library. If you don't, you have to insert them in front or the system will say he can't find the type you are using.
And .clear( ) is a function not an argument. I compiled this code on VC++2003 and it works like a charm and prints the names correctly.
#include <stdio.h>
#include <map>
#include <string>
//using namespace std;
typedef std::map<std::string, std::string> MyMap;
MyMap TestMap;
int main() {
std::string chan( "#Channel" ); //keytype
std::string mark( "Mark" ); //datatype
TestMap.insert( MyMap::value_type( chan, mark ) );
MyMap::iterator it = TestMap.find( chan );
//this should print Mark
if ( it != TestMap.end( ) ) {
printf( (*it).second.c_str( ) );
printf("\n");
}
//change #channel value from Mark to Harry
TestMap.clear( );
std::string harry( "Harry" );
TestMap.insert( MyMap::value_type( chan, harry ) );
//this should now print Harry
if ( it != TestMap.end( ) ) {
printf( (*it).second.c_str( ) );
printf("\n");
}
return 0;
}