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

Setting vector<double> as choice values of wxComboBox

本文关键字:wxComboBox 选择 gt 向量 lt double 设置      更新时间:2023-10-16

我正在用GUI创建我的第一个C 程序。我正在使用代码:: blocks v16.01和wxwidgets v3.03。我发现在WXCOMBOBOX类构造函数中,代表选择的类型是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 );