【发布时间】:2015-06-02 15:17:10
【问题描述】:
所以,我是编程新手,遇到了这个问题。
我编写了一个控制台应用程序,可以在其中将对象添加到 STL 矢量。
一些代码:
Element.h(这个类的对象我存储在 Vector 中)
class Element
{
private:
string speaker_name;
string color_membrane;
string color_main;
string size_main;
string color_terminals;
string size_terminals;
public:
Element();
~Element();
string Get_color_membrane();
string Get_color_main();
string Get_size_main();
string Get_color_terminals();
string Get_size_terminals();
string Get_speaker_name();
void Set_color_membrane(string);
void Set_color_main(string);
void Set_size_main(string);
void Set_color_terminals(string);
void Set_size_terminals(string);
void Set_speaker_name(string);
Doc.cpp(带向量的类)
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "Doc.h"
using namespace std;
vector <Element> MyElements;
void Doc::Add_item(Element const& TempElement)
{
MyElements.push_back(TempElement);
}
应用程序.cpp
Doc doc;
Element TempElement;
cout << "Add new Element" << endl;
cout << "Input NAME of speaker" << endl;
cin >> temp_string;
TempElement.Set_speaker_name(temp_string);
cout << "Input COLOR of membrane" << endl;
cin >> temp_string;
TempElement.Set_color_membrane(temp_string);
cout << "Input COLOR of main body of speaker " << endl;
cin >> temp_string;
TempElement.Set_color_main(temp_string);
cout << "Input stroke SIZE of membrane & main body" << endl;
cin >> temp_string;
TempElement.Set_size_main(temp_string);
cout << "Input COLOR of terminals" << endl;
cin >> temp_string;
TempElement.Set_color_terminals(temp_string);
cout << "Input stroke SIZE of terminals" << endl;
cin >> temp_string;
TempElement.Set_size_terminals(temp_string);
doc.Add_item(TempElement);
问题是:我正在 WxWidgets 中编写一个基于窗口的应用程序。
我的项目如下所示:
(这只是为了测试目的 - 它什么都不做)
而且,现在我想创建一种方法,从 STL 向量(红色箭头指向的位置)制作某种对象列表, 它应该或多或少像这样:
并且能够与STL向量通信
提前感谢您的帮助。
~保温杯
【问题讨论】:
-
完全不清楚你在问什么。尝试缩小问题的范围。
-
你想让我解释什么?
-
我想列出来自 STL 向量的对象(图片您可以在我的帖子中看到)