#47667: c++ map


s290006@student.cysh.cy.edu.tw (風堇一生推)


看到我就想用map做

(不想寫8個if/else)

但用map的話怎麼判斷其他種狀況呢(不屬於星期一到日)

map<string,int> weekday=({......})

if (weekday.count(s)) {

cout << weekday[s] << '\n';

}

else {

cout << "error" << '\n';

}

m.count(s) return s在map中出現的次數,對map而言必為1 or 0