0

わかりました、タイトルで質問を説明する方法がわかりませんでしたが、基本的に達成しようとしているのは、Allegro を使用した「コマンド ライン」風の GUI です。グラフィックスは正常に動作しますが、履歴を保持する方法が明らかな理由で機能していません。そもそも私が本当に愚かだった値を保存するためにマップを使用しています。以前の履歴と同じ履歴にコマンドを追加するたびに、以前の履歴が消えます。私が知りたいのは、マップにあるように値が上書きされないように値を保存する方法はありますか?

これが私の現在の方法です

Point という構造体があります

struct Point {
    float x, y;

    Point() { this->x = 10.0; this->y = 440.0; }
    Point(float x, float y): x(x), y(y) { };
};

これを使用して、プログラムのグラフィック処理部分で使用されるテキストが表示されるポイントを保存します。

これは、HistoryManager.h で定義された HistoryManager クラスです。

class HistoryManager {

    public:
        HistoryManager();
        ~HistoryManager();
        bool firstEntry;
        map<string, Point> history;

        void add_to_history(string);

    private:
        void update();
};

HistoryManager.cpp の定義は次のとおりです。

HistoryManager::HistoryManager() { this->firstEntry = false; }

HistoryManager::~HistoryManager() { }

void HistoryManager::add_to_history(string input) {

    if (!this->firstEntry) {
        this->history[input] = Point(10.0, 440.0);
        this->firstEntry = true;
    } else {
        this->update();
        this->history[input] = Point(10.0, 440.0);
    }
}

void HistoryManager::update() { 

    for (map<string, Point>::iterator i = this->history.begin(); i != this->history.end(); i++) {
        this->history[(*i).first] = Point((*i).second.x, (*i).second.y-10.0);
    }
}

ベクトルはオプションだと思いますが、値をペアにする方法はありますか?

4

1 に答える 1

1

使用するstd::pair

std::vector< std::pair <std::string, Point> > >

または、独自の構造体を宣言するだけです

struct HistoryEntry
{
    std::string input;
    Point point;
};

std::vector<HistoryEntry>
于 2013-05-05T22:12:30.817 に答える