[英]C++ - Conversion std::basic_string<char>
Brace yourselves! 支撑你自己! C++ newbie question incoming: C ++新手问题传入:
Can someone explain to me why this error occurs and how should I fix it? 有人可以向我解释为什么会出现这种错误,我该如何解决?
std::vector<std::string> options = vectorOGROptions_.get()
I want to get options
var as std::vector<std::string>
but it seems my vectorOGROptions property returns a different type.. 我想将options
var作为std::vector<std::string>
但似乎我的vectorOGROptions属性返回一个不同的类型。
error: conversion from ‘const std::basic_string<char>’ to non-scalar type ‘std::vector<std::basic_string<char> >’ requested
Your get()
function returns string
, but you are trying to initialize vector with this string, that's not allowed. 你的get()
函数返回string
,但是你试图用这个字符串初始化vector,这是不允许的。
You can use something like this 你可以使用这样的东西
std::vector<std::string> options;
options.push_back(vectorOGROptions.get());
You are trying to assign to a vector a string. 您正在尝试将向量分配给字符串。 You cannot do this. 你不可以做这个。 Use an initialiser list. 使用初始化列表。
std::vector<std::string> options{vectorOGROptions_.get()};
The error says that this get()
function returns const std::basic_string<char>
, which is nothing but std::string
. 错误说这个get()
函数返回const std::basic_string<char>
,这只不过是std::string
。 Use vector's push_back()
method: 使用vector的push_back()
方法:
std::vector<std::string> options;
options.push_back(vectorOGROptions_.get());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.