Thread: syntax error of map?

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    48

    syntax error of map?

    Dear there, in my .cpp file, the compiler complains there is a syntax error for the last line? what's the error? thanks.
    Code:
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <deque>
    #include <cassert>
    #include <cstddef>
    #include "commonio.hpp"
    #include <map>
    #define P(x) cout << #x << " : " << x << endl;
    using namespace std;
    
    typedef map<string, time_t> Prodrange;
    Prodrange pstart, pend;
    pstart["AUD_CAD"]=1191171604;

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    What error does it say? There could be a number of things wrong with this snippet.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You can't have anything but declarations outside of functions.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    48

    a global look-up table?

    hey, thanks for reply. all I want is a global look-up table, mapping string to time_t. For the code I attached, what I want is to be able to use
    Code:
    pstart["USD_CAD"]
    wherever I need a time_t value.

    Is there a good way to do it? Thanks.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You could set the values at the beginning of main. You could create a function that returns a map initialized with the data and initialize the map before main.

    Code:
    map<std::string, int> globals = function_filling_map();
    Boost.Assign also has nice things for initializing containers, e.g:

    Code:
    #include <boost/assign.hpp>
    
    std::map<std::string, int> globals = boost::assign::map_list_of
        ("Hello", 1)
        ("world", 2)
        ("!", 3);
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    48

    finally I choosed enum, thanks anyway

    I played a while trying the techniques suggested, it worked out. I further tried to use singleton to setup global variables. Eventually I said to myself, these are constants, not variables, so I fell back to the old and good enum. Thanks for the suggestions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

Tags for this Thread