스칼라를 bool로 구문 분석하려고합니다.연산자를 오버로드하는 방법 >> bool
YAML::operator>><bool> (node=..., [email protected]) at /usr/include/yaml-cpp/nodeimpl.h:24
그리고 난 안 '예'또는 '아니오'에 문자열이 'YAML :: InvalidScalar'를 얻을 :
#include <yaml.h>
#include <iostream>
#include <sstream>
#include <string>
void operator>> (const YAML::Node & node, bool & b)
{
std::string tmp;
node >> tmp;
std::cout << tmp << std::endl;
b = (tmp == "1") || (tmp == "yes");
}
int main()
{
bool b1, b2;
std::stringstream ss("key: да\notherkey: no");
YAML::Parser parser(ss);
YAML::Node doc;
parser.GetNextDocument(doc);
doc["key"] >> b1;
doc["otherkey"] >> b2;
std::cout << b1 << std::endl;
std::cout << b2 << std::endl;
return 0;
}
그러나 더 복잡한 경우 템플릿 연산자
가 사용됩니다 이 예제는 작동합니다.
와우. 내가 네임 스페이스 YAML {}에 오버로드 된 연산자를 둘러 쌌습니다. 그리고 지금 그것은 작동합니다 ... – Igor