map

std::unordered_map with custom value type, operator[]

自作多情 提交于 2020-01-05 08:06:46
问题 I'm trying to use std::unordered_map, as shown in the example here. class CSVRecord { public: CSVRecord(string csvLine) : _fields(vector<string>()) {...} vector<string> _fields; }; int main(int argc, char* argv[]) { unordered_map<string, CSVRecord> m; CSVRecord rec = CSVRecord("test"); m["t"] = rec; return 0; } However, m["t"] = rec gives an error: no matching function for call to ‘CSVRecord::CSVRecord()’ . I used m.insert(pair<string, CSVRecord>("t",rec)) instead, but I wonder why the

const char* not found in map find

送分小仙女□ 提交于 2020-01-05 07:58:12
问题 I have a small program, I am trying to search for a particular string in the map, I get correct result if I pass static const string "us" to find but it doesn't work if I copy a string to pointer. I somehow think that it is trying to compare the address of the string that is passed. I am planning to get rid of std::string from due to some reason. using namespace std; static struct MarketLang { const char* market; const char* lang; } market_lang[] = { {"us", "all"}, {"el", "en,fr,it,de,es"}, {

How to #include hash with ext, tr1, or __gnu_cxx in XCode, C++

╄→尐↘猪︶ㄣ 提交于 2020-01-05 05:53:28
问题 I'm trying to work with the google-sparsehash library and I'd like to include the hash library described in the link, using ext::hash; // or __gnu_cxx::hash, or maybe tr1::hash, depending on your OS and I've tried one of each: #include <ext/hash> #include <ext> #include <__gnu_cxx> #include <tr1> which none worked with XCode. I've also "using", where I was told that __gnu_cxx does not contain "hash". How do I describe this library to XCode (3.2.6) on OS X (10.6.8)? Or more generally, where is

Is there a better (more efficient) way to find if a string can be formed from chars of another string?

こ雲淡風輕ζ 提交于 2020-01-05 05:51:30
问题 This is interesting because it's a possible interview question, so it would be good to know the most efficient algorithm for this problem. I came up with a solution (which contains elements of other people's solutions) that requires a map<char, int> to store letters from the first string as keys, and numbers of their occurrences as values. The algorithm then looks through each letter in the container string and checks if there's already an entry in the map. If so, decrement its value until it

How can I add a north arrow to a leaflet.js map?

人走茶凉 提交于 2020-01-05 04:14:15
问题 Is there an easy way to add a north arrow to a leaflet.js map? I have searched a bit online but I cannot find much. 回答1: You can add a control that contains a div with your north arrow image: var north = L.control({position: "bottomright"}); north.onAdd = function(map) { var div = L.DomUtil.create("div", "info legend"); div.innerHTML = '<img src="your-north-arrow.png">'; return div; } north.addTo(map); See Leaflet's control documentation for more info on positioning and other options. 来源:

Using octave to map vector values

折月煮酒 提交于 2020-01-04 15:31:25
问题 Can anyone explain how the following code: Y(Y==0) = -1 sets all values of 0 to -1. For example for: Y = [1 1 1 0 0 0 1] we get: Y = [1 1 1 -1 -1 -1 1] What is confusing me is that Y==0 does not return a vector of indices. An if I try to use the vector Y==0 directly I get the error: Y([0 0 0 1 1 1 0]) = -1 error: subscript indices must be either positive integers or logicals I would have naturally opted for: Y(find(Y==0)) = -1 and would like to know why the above does not use find TIA 回答1:

Android - How to know if mapView is properly loaded?

纵然是瞬间 提交于 2020-01-04 04:29:21
问题 I am having trouble in detecting if mapview is loaded in my android map appication. In OnCreate method, when I assign the map URL, I want to know if any problem occured. Problems may occur due to my internet connection or any other problems like loading the map from REST services. Here is my code block; map.addLayer(newArcGISDynamicMapServiceLayer("any map URL")); after this point, I try to use a control like if(map.isLoaded==false) but it does not work, although map is loaded properly it

How do I find all the keys common in 2 maps?

雨燕双飞 提交于 2020-01-04 03:50:56
问题 I have 3 maps: map<string, vector<int> > map1 map<string, vector<int> > map2 map<string, vector<int> > map3 I need to create a third map with all the strings existing in both map1 and map2 with their corresponding vectors. Thing is, even if the strings are same, their vectors can be different and i have to append all the vectors from both the common strings into 1 vector. This is what I'm trying but I'm kind of lost: for(map<string, vector<int> >::iterator it1=map1.begin(); it1 != map1.end();

How to get coordinates of an svg?

£可爱£侵袭症+ 提交于 2020-01-04 02:58:28
问题 How can I find out the coordinates of an svg? I have an Adobe Illustrator file that contains a map, this has been drawn and separated into US states, how can I find the coordinates of each state? I'm just using the US map as an example, I'm going to potentially use this technique for several other maps (much more local!!). 回答1: SVG have an XML structure. The states will be in <path> tags, hopefully with the name of the state somewhere as an attribute. The coordinates of a path are defined by

How can I color ocean with topojson in d3 when I have coordinate info for land?

試著忘記壹切 提交于 2020-01-04 01:30:46
问题 I am learning topojson with d3. I have coordinate information for land, which is rendered correctly. Then, how can I add color to ocean (basically outside land)? I tried coloring graticule, but doesn't fill up the entire map and leaves empty spots. The visualization is hosted on http://jbk1109.github.io/ var projection = d3.geo.stereographic() .scale(245) .translate([width / 2, height / 2]) .rotate([-20, 0]) .clipAngle(180 - 1e-4) .clipExtent([[0, 0], [width, height]]) .precision(.1); var