I have this code, but when i type in one comand and then the next comand it does doe the comand i type in but the first comand i typed in.
* I think it is becuase i dont clean my vector string, if so how do i clean it. And if not, what is wrong.

Note this is only part of the code, i dont want to give away my entire project...

int main()
{
    stringstream ss;
while(1)
{


    cout<<"\n>: ";
    getline(cin, input);

    ss << input;

    while(ss >> temp)
    {
        comand.push_back(temp);
    }

    if(comand[0] == "gencode" && comand[1] != "" && comand[2] != "" && comand[3] != "")
    {
        GenCode(comand[1], comand[2], comand[3]);
    }
    else if(comand[0] == "encrypt" && comand[1] != "" && comand[2] != "")
    {
        ifile = comand[1];
        ofile = comand[2];
        Encrypt();
    }
    else if(comand[0] == "decrypt" && comand[1] != "" && comand[2] != "")
    {
        ifile = comand[1];
        ofile = comand[2];
        Decrypt();
    }
    else if(comand[0] == "exit")
    {
        exit(1);
    }
    /*else
    {
        Help();
    }*/
}
    return 1;
}

If i type:

    gencode hello world test

It genereates the code but then when i type:

    encrypt C:\Users\Users\Desktop\INPUTFILE.txt C:\Users\User\Desktop\OUTPUTFILE.txt

Then i generates the code again, so the vectors dont clean up or is it another bug, if it is, please tell me how to fix it...

Oh and Thanks....

Recommended Answers

All 5 Replies

You don't clear command anywhere in that snippet. If it's not cleared anywhere else, then I'm not surprised that the previous data remains. After each iteration of the outer loop you can just say command.clear() to make it empty.

I'm supose to put it where, sorry i am teaching myself C++, dont know all the words yes...

while (1)
{
    // All your stuff

    comand.clear(); // Here
}

Oh thanks, will se if that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.