English 中文(简体)
病媒问题病媒
原标题:A vector of vector problems

我试图通过一份扼杀清单,发现某一特性位于上述扼杀中。 然后,我根据特性发生地/发生地的情况,在某种病媒中储存体。 I m在完成手术之前,在以下法典中出现错误。 我已经用了半个时间来审视这个问题,似乎不会发现任何错误。

vector< vector<string> > p;
for(list< string >::iterator ix = dictionary.begin(); ix != dictionary.end(); ix++)
{
    int index = contains(*ix, guess);
    index++;

    p.at(index).push_back(*ix); //0 will contain all the words that do not contain the letter
                                //1 will be the words that start with the char
                                //2 will be the words that contain the the char as the second letter
                                //etc...
}



int contains(string str, char c)
{
    char *a = (char *)str.c_str();
    for(int i = 0; i < (str.size() + 1); i++)
    {
        if(a[i] == c)
            return i;
    }
    return -1;
}
最佳回答

vector< vector > p defines p as empty vector. You must have vector elements added to it before using vector::at(). For example:

const size_t MAX_LETTERS_IN_WORD = 30;
vector< vector<string> > p(MAX_LETTERS_IN_WORD);

/* same as before */

作为一种替代办法,在使用(a)点之前,可以检查(b)点,并根据需要将额外内容推到底。

问题回答

时间错误的问题可能在于,在尚未出现的情况下,你可以进入病媒p<>/code>。 在您获得具体指数之前,你必须使病媒空间。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?