Recieving "string subscript out of range" error
<p>Doing this assignment where I parse information into a struct and I keep recieving an error saying "string subscript out of range" when trying to test. Cant figure out where I went wrong.</p>

<p>here is the struct</p>

<pre><code>struct baby_type {

std::string name;
std::vector&lt;int&gt; yearsCount;
    int total;
} ;
</code></pre>

<p>here is my function</p>

<pre><code>baby_type Parse_Line(const std::string line )
{

baby_type baby;
std::string name;
std::string year;// = "0000";
std::string total;
int i = 0;
int k = 1;
int LengthOfOccurences = 0;
int DigitOfOccurences = 0;

while (line.at(i) != ',') {
    name[i] = line.at(i);
    i++;
}
baby.name = name;
i++;

while (k &lt; 100) {   
    if (line.at(i) == ',') {
        year.resize(LengthOfOccurences);
        baby.yearsCount.at(k) = std::stoi(year);
        //year = "0000";
        i++;
        k++;
        DigitOfOccurences = 0;
        LengthOfOccurences = 0;
    }
    else {  
        year.at(DigitOfOccurences) = line.at(i);
        i++;
        LengthOfOccurences++;
    }
}

int m = 0;
int LengthOfLine = line.length();

while (i &lt; LengthOfLine) {
    total.at(m) = line.at(i);
    m++;
    i++;
}

baby.total = std::stoi(total);

return baby;
}
</code></pre>