Hi all!

I am working on creating an SMS language translator (SMS -> real English), and I am having trouble initializing a map for the SMS -> English codes.

My code is below:

 map<string, string> THE_SMS_CODES{
    ".02","Your (or my) two cents worth",
    "10X", "Thanks",
    "2MI","Too much information",
    "2U2"   ,"To You Too",
    "4COL","For Crying Out Loud",
    "420"   ,"let's get high",
    "<chuckle>","the speaker chuckles",
    "<frown>","the speaker is frowning",
    "<g>","Grin",
    "<grin>","the speaker is grinning",
    "<smile>","the one writing the message is smiling",
    "<smirk>","the one writing the message is smirking",
    "<wink>","the one writing the message is winking",
    "[$X$]","No spam !!",
    "JK","Just Kidding",
    "?","I have a question",
    "?RUD","What are you doing?",
    "!","I have a comment",
    "A-OLs","Administrators On-Line",
    "AAMOF","As A Matter Of Fact",
    "ADN","Any Day Now",
    "AFAIC","As Far As I'm Concerned",
    "AFAIK","As Far As I Know",
    "AFAIR","As Far As I Remember",
    "AFJ","April Fools Joke",
    "AFK","Away From the Keyboard",
    "AISI","As I See It",
    "ANFAWFOS","And Now For A Word From Our Sponsor",
    "ANFSCD","And Now For Something Completely Different",
    "AS","Another Subject",
    "ASAP","As Soon As Possible",
    "ASAYGT","As Soon As You Get This",
    "ASL","Age, Sex, Location",
    "ASLA","Age, Sex, Location), Availability",
    "ATSL","Along The Same Line",
    "AV","Audio Visual",
    "AWC","After While), Crocodile",
    "AWGTHTGTTA","Are We Going To Have To Go Through This Again?",
    "AWHFY","Are We Having Fun Yet?",
    "AWTTW","A Word To The Wise",
    "AYOR","At Your Own Risk",
    "B4N","Bye For Now",
    "BAC","Bad A**ed Chick",
    "BAK","Back At Keyboard",
    "BBFN","Bye Bye For Now",
    "BBIAB","Be Back In A Bit",
    "BBIAF","Be Back In A Few",
    "BBL","Be Back Later",
    "BBR","Burnt Beyond Repair",
    "BC","Because",
    "BCNU","Be seein’ you",
    "BEG","Big Evil Grin",
    "BF","Boy Friend",
    "BFN","Bye For Now",
    "BFD","Big Fricking Deal",
    "BFF","Best Friends Forever",
    "BIF","Before I Forget",
    "BION","Believe it or not",
    "BOBFOC","Body Off Baywatch, Face Off Crimewatch",
    "BOHICA","Bend Over), Here It Comes Again",
    "BOT","Back On Topic",
    "BRB","Be Right Back",
    "BRS","Big Red Switch",
    "BTA","But Then Again",
    "BTAIM","Be That As It May",
    "BTHOM","Beats The Hell Outta Me",
    "BTOBD","Be There Or Be Dead",
    "BTW","By The Way",
    "BWL","Bursting With Laughter",
    "BWQ","Buzz Word Quotient",
    "BYE","Response to BYE?",
    "BYE?","Are you ready to say goodbye?",
    "BYKT","But You Knew That",
    "BYOB","Bring Your Own Bottle",
    "BYOM","Bring Your Own Mac",
    "C&G","Chuckle and Grin",
    "CADET","Can't Add), Doesn't Even Try",
    "CID","Crying In Disgrace",
    "CMIIW","Correct Me If I’m Wrong",
    "CO","Conference or Company",
    "CPP","C Plus Plus or C++",
    "CRS","Can't Remember Sh**",
    "CSG","Chuckle, Snicker, Grin",
    "CU","See You",
    "CU2","See You, Too",
    "CUL","See you later",
    "CUL8R","See You Later",
    "CULA","See You Later, Alligator",
    "CWYL","Chat With You Later",
    "CYA","See Ya (or Cover Your Ass)",
    "CYAL8R","See You All Later",
    "CYOA","Cover Your Own Ass",
    "D8","Date",
    "DAC","Duck And Cover",
    "DAU","Dosen't Add Up",
    "DIIK","Damned If I Know",
    "DIKU?","Do I Know You?",
    "DILLIGAD","Do I Look Like I Give A Damn?",
    "DIY","Do It Yourself",
    "DK","Don’t Know",
    "DLTBBB","Don't Let The Bed Bugs Bite",
    "DNFTT","Do Not Feed The Trolls",
    "dotgov","A government official (from the .gov of government domain names)",
    "DTRT","Do The Right Thing",
    "DWIMC","Do What I Mean, Correctly",
    "DWIMNWIS","Do What I Mean, Not What I Say",
    "WAYD","What Are You Doing",
    "LMK","Let Me Know",
    "LYMY","Love You Miss You"};

transform(THE_SMS_CODES.begin, THE_SMS_CODES.end, THE_SMS_CODES.begin, ::tolower);



transform(THE_SMS_CODES.begin, THE_SMS_CODES.end, THE_SMS_CODES.begin, ::tolower);

In line 1 (map<string,string> THE_SMS_CODES{), I am getting the message No matching constructor for initialization of 'map<string,string>'.

Then, I get another message for the transform algorithm (to transform all of the sms-english pairs to lowercase). The message is: C++ requires a type specifier for all declarations.

Please help as I do not know what to do.

Thanks!!

You're missing some braces. Each pair gets wrapped in braces.

map<string, string> THE_SMS_CODES = 
  {{".02", "Your (or my) two cents worth"},
   {"10X", "Thanks"}};

Make sure your compiler is expecting C++11.

Fixed the syntax, but the error on the transform and ::tolower algorithm still persists. How can I lower the keys and values in the map?

The keys in the map are const objects: const std::string; they can't be modified directly inside the map.

Something like this, perhaps:

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

std::string to_lower( const std::string& str )
{
    std::string lc ;
    for( char c : str ) lc += std::tolower(c) ;
    return lc ;
}

std::map< std::string, std::string > to_lower( const std::map< std::string, std::string >& map )
{
    std::map< std::string, std::string > lc ;
    for( const auto& pair : map ) lc.emplace( to_lower(pair.first), to_lower(pair.second) ) ;
    return lc ;
}

int main()
{
     std::map< std::string, std::string > the_sms_codes
     {
        { ".02",  "Your (or my) two cents worth" },
        { "10X",  "Thanks" },
        { "2MI",  "Too much information"},
        { "2U2",  "To You Too" },
        { "4COL", "For Crying Out Loud" }
     };

     the_sms_codes = to_lower(the_sms_codes) ;

     for( const auto& pair : the_sms_codes ) std::cout << pair.first << " - " << pair.second << '\n' ;
}

http://coliru.stacked-crooked.com/a/a8002a215a00beca

Or initialise them as lower case strings:

std::map< std::string, std::string > the_sms_codes
{
    { to_lower(".02"),  to_lower("Your (or my) two cents worth") },
    { to_lower("10X"),  to_lower("Thanks") },
    // ...
};
This question has already been answered. Start a new discussion instead.