我第一次使用unordered_map。当我尝试在Xcode中编译代码时它工作正常,但是当我尝试使用g ++在终端中编译它时它会拖曳
error: expected expression
u.insert({name, i});
我看不出问题出在哪里。 这是代码
#include <iostream>
#include <string>
#include <unordered_map>
std::unordered_map<std::string, int> u;
std::string name;
int main()
{
char ch;
int i =1;
std::cout<<"Do you want to enter. (Y/N): ";
std::cin>>ch;
while ((ch != 'N') && (ch != 'n')) {
std::cout<<"Enter ";
getline (std::cin,name);
auto search = u.find(name);
if(search != u.end()) {
std::cout << "Found " << search->first << " at pos " << search->second << '\n';
}else{
std::cout << "Not found\n";
u.insert({name, i});
i++;
}
}
return 0;
}