Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ vector


ghost's Avatar
0 0

i have this vector

    example.push_back("tab");         //Add tab onto the vector
    example.push_back("tab\n");        //Add tab to the end
    example.push_back("33\n");        //Add 33 to the end
    for(int x=0; x<example.size(); x++)
    {
        cout<<example[x]<<" ";    //Should output: tab tab 33
    }```
but i have few problems. first of all, when i compile it i will get this output:
```markuptab
<thereisaspace>tab
<thereisaspace>33```
and i need it without that space. i dont know what is wrong there.
also, what about if i need to add the another entry, for example called tab2, at before the tab, not at end of vector?
and what about if i want to delete the value 33?
thanks.

ghost's Avatar
0 0
example.push_back("tab\n"); //Add tab to the end
example.push_back("33\n"); //Add 33 to the end```

```markuptab tab
<space>33
<space>```

that should be the output

and the vector class in C++ has a member function called insert

ghost's Avatar
0 0

thanks. i know about insert and erase methods, but i cant find the parameter which add the string where i need.