XGBRegressor c++ loading

Hi.
I’m having trouble loading my model in c++ and windows

In Python I train using:
xgbr = XGBRegressor(max_depth=5, random_state=3)
xgbr.fit(X_train, y_train, eval_set=[(X_train, y_train), (X_test, y_test)])

then I save using :
xgbr.save_model(‘c:/temp/xgbr.model’)

Then in windows I try loading using:
std::string modelPath = “c:/temp/xgbr.model”;
xgboost::Lerner* pLearner = xgboost::Learner::Create({});
auto learner = std::make_unique<xgboost::Learner>(*pLearner);
std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(modelPath.c_str(), “r”));
learner->Load(fi.get());

It crashed when running the last line.
Can anyone tell what am I doing wrong?
Thanks!

Use LoadModel() method instead:

std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(modelPath.c_str(), "r"));
pLearner->LoadModel(fi.get());