将 vector<double> 设置为 wxComboBox 的选择值

Setting vector<double> as choice values of wxComboBox

我正在用 GUI 创建我的第一个 C++ 程序。 我正在使用 Code::Blocks v16.01 和 wxWidgets v3.03。 我发现在wxComboBox class构造函数中,代表选择的类型是wxArrayString。我曾尝试将向量转换为向量,然后再转换为向量和 wxArrayString,但失败得很惨...

我的问题是如何设置wxComboBox对象的默认选择值? 最好我希望它们填充在程序执行期间创建的向量值。

代码如下:

#include <iostream>
#include <vector>
#include <fstream>
#include <sstream> 
using namespace std;

vector <double> vector_double;
vector <string> vector_string;
vector <wxString> vector_wxstring;

void convert_double_to_string(vector<double> &dbl, vector <string> &str)
{
    for (int i = 0; i < dbl.size(); i++)
    {
        ostringstream stream;
        stream << dbl[i];
        str.push_back(stream.str());
    }
}
void convert_string_to_wxString(vector<string> & str, vector <wxString> &wxstr);
{
    for (int i = 0; i < str.size(); i++)
    {
        wxstr.push_back(_(str[i]));
    }
}
void main()
{
    /////////

    // here setting vector_double's values

    //////////

   convert_double_to_string(vector_double, vector_string);
   convert_string_to_wxString(vector<string> vector_string, vector_wxstring);
}

这就是我得到的。虽然字符串转换为 wxString 不起作用。即使可以,我也不知道如何将它插入 wxArrayString。

大致如下:

wxComboBox * cbo = new wxComboBox( ... );
wxArrayString as;
for ( auto& s : vector_string )
  as.Add( s );
cbo->Set( as );