C++ - 转换 std::basic_string<char>

标签 c++ string type-conversion

振作起来! C++新手问题来袭:

有人可以向我解释为什么会出现此错误以及我应该如何解决它吗?

std::vector<std::string> options = vectorOGROptions_.get()

我想得到 options可变为 std::vector<std::string>但我的 vectorOGROptions 属性似乎返回了不同的类型..

error: conversion from ‘const std::basic_string<char>’ to non-scalar type ‘std::vector<std::basic_string<char> >’ requested

最佳答案

您的 get() 函数返回 string,但您试图用该字符串初始化 vector,这是不允许的。

你可以这样使用

std::vector<std::string> options;
options.push_back(vectorOGROptions.get());

关于C++ - 转换 std::basic_string<char>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20001237/

相关文章:

ios - 刷卡中的数组获取第一个元素

c++ - reinterpret_cast 转换链正确性

memory - 将字符串转换为 &strs 时,切片和显式重新借用之间有区别吗?

C++ 错误 C2440 : 'initializing' : cannot convert from 'class name' to 'same class name'

c++ - 在模板中初始化静态成员

Java - 将多个字符串转换为图像格式

c++ - int 在 operator== 中显示为 std::basic_ostream<char>

c++ - 返回二维 vector 的结束索引

c++ - 为什么我的代码不渲染灰度效果

java - 捕获字符串上匹配字符(单个或重复)之间的所有字符