2

I'm an amateur so bear with me, but I've hit the end of my research with no solution for this.

This code complies fine but when I debug, it's apparent that the procedure exists upon reaching the for loop, and never executes what is within it (which is what I need to do).

void insertWord(list<Word> &words, string str)
{
    list<Word>::iterator itr;
    for (itr = words.begin(); itr != words.end(); itr++ ) //EXITS HERE
    {
        if (str == (*itr).aWord)
        {
            (*itr).iterateCount();
            return;
        }
        if (str > (*itr).aWord)
        {
            words.push_back(Word(str));
            return;
        }
    }
}

I don't understand why the for loop is never executed. It just skips right to the end of the function.

NB: "Word" is a custom class to hold a string and an int(how many of that string there are). If any more info is required please ask, I'm dying here! Thanks.


The calling thread must be STA

The error Im getting : The calling thread must be STA, because many UI components require this.

So I have an android application which generates a bill of materials on the server side. Therefore a new UI has to be generated for the bill of materials. When I try to add a product to the BOM..this is the error I am getting. How do I go about it. An solution allowing me to host the service the android application is using is already running. The BOM application is a part of this solution.

4

2 に答える 2

2

リストが空のように見えるためitr==words.end()、ループ内のコードは実行されません。

于 2012-05-02T06:55:03.813 に答える
0

You could use a std::map:

std::map<Word, int> histogram;

histogram[Word("hello")] += 1;
histogram[Word("hello")]++; //  equivalent

histogram[Word("vertigo")]++;
于 2012-05-02T07:09:15.957 に答える