#include<iostream>
#include<map>
#include <type_traits>
using namespace std;
enum SendMode {
text,
bin
};
int main(int argc, char* argv[])
{
std::map<string, string>a;
a["key"] = "text";
map<string, string>::iterator it;
for ( it = a.begin(); it !=a.end(); it++)
{
cout << it->first << endl;
cout << it->second << endl;
if (it->second.find(SendMode::bin))//我的目的是为了判断map value是不是SendMode中的一个值,但是不知为什么还会输出yes
{
cout << "yes" << endl;
}
}
}
那你要看find函数的返回值是什么了,如果找不到,应该返回为-1,if(-1)是成立的,所以会输出yes
应该是if (it->second.find(SendMode::bin) >= 0)
#include<iostream>
#include<map>
#include <type_traits>
#include<string>
using namespace std;
enum SendMode {
text,
bin
};
int main(int argc, char* argv[])
{
std::map<string, string>a;
a["key"] = "text";
map<string, string>::iterator it;
for (it = a.begin(); it != a.end(); it++)
{
cout << it->first << endl;
cout << it->second << endl;
cout << it->second.find("text") << endl;
cout << it->second.find(SendMode::bin) << endl;
cout << it->second.find(SendMode::text) << endl;
cout << it->second.npos << endl;
if (it->second.find(SendMode::bin)!=it->second.npos)//我的目的是为了判断map value是不是SendMode中的一个值,但是不知为什么还会输出yes
{
cout << "yes" << endl;
}
}
system("pause");
}