0

たとえば、次のようなオブジェクトのリストがあります。-std::listのようなリスト内の長方形オブジェクト。リストから(一度に)50個のオブジェクトのリストを取得し、各長方形から長さと幅として個々の要素を取得し、最初の50個、次に次の50個のサイズ(長さ、幅)の文字列を形成する必要があります。最後までなど...

ブースト機能を使用してこれをコーディングする方法を見つけようとしています。

4

1 に答える 1

1

You didn't give any details of how those strings should be formatted, but the general iteration could be of this form:

int j;
string work;
vector<string> strings;
for(list<Rectangle>::iterator i = l.begin(); i != l.end(); i++,j++)
{
    int len = i->length, br = i->breadth;
    work += something_based_on(len,br);
    if(j == 50)
    {
        strings.push_back(work);
        work.clear();
        j = 0;
    }
}

This doesn't use boost, though.

于 2012-11-02T19:06:37.233 に答える