2013-11-15 54 views
0

Brace yourselves! C++新手問題傳入:C++ - 轉換std :: basic_string <char>

有人可以向我解釋爲什麼會發生此錯誤,我應該如何解決它?

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

我想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 
+0

假設你正在使用C++ 03,而不是C++ 11,做'的std ::矢量選項(1,vectorOGROptions_.get());'。 – legends2k

回答

2

get()函數返回string,但你想用這個字符串初始化向量,這是不允許的。

您可以使用類似這樣

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

您正在嘗試將分配給一個矢量的字符串。你不可以做這個。使用初始化列表。

std::vector<std::string> options{vectorOGROptions_.get()}; 
0

錯誤說,這get()函數返回const std::basic_string<char>,這只不過是std::string。使用矢量的push_back()方法:

std::vector<std::string> options; 
options.push_back(vectorOGROptions_.get()); 
相關問題