Unsual end with vectors

Hi everyone.

I'm having problems with a code using vectors, the code sintax is right, but it terminate in a unespected way.

The prompt says that the application has requested the runtime to terminate it in a unsual way.

My program read the input of the user and store it in a string, then i put the content of the string in a vector, then i read the vector to find some caracters, at this point is the error.

string eqc;
    vector <char> mem_cal,buffer;
    getline (cin,eqc);
    
    for (int i = 0; i <= eqc.length(); i++) {
        mem_cal.push_back (eqc.at(i));}
        
    for (int i = 0; i <= mem_cal.size(); i++) { 
        if (mem_cal.at(i) == '+'||mem_cal.at(i) == '-') {if (mem_cal.at(i+1) != '+'||mem_cal.at(i+1) != '-') break;} 
        buffer.push_back(mem_cal.at (i));
        }


How can i do to avoid this problem ?

Ps. I still learning english, so please forgive me for any writing error.

Tanks.
You are iterating out of bounds on your string/vector. Use i < epc.length() and i < mem_cal.size() instead.

Also, you should use [code][/code] tags for code.
Topic archived. No new replies allowed.