完全删除向量 c++

发布于 2024-08-02 17:42:24 字数 427 浏览 3 评论 0原文

我在从“多维向量”中删除向量时遇到问题

我想实现这一点:

    1 1 1 1         1 1 1 1
    2 2 2 2         2 2 2 2
    3 3 3 3         4 4 4 4 
    4 4 4 4



 for example 

vector<vector<int>>vec;
    for i...//give vec values...
    vec[3].erase(vec.begin(),vec.end());

似乎使用向量.erase()或向量.clear()在“第三行”留下一个空向量 有没有办法完全删除该向量,以便

vec[3]=4 4 4 4

感谢一个伟大的论坛...... /布克斯

I'm having problems removing a vector from a "multidimensional vector"

I would like to achieve this:

    1 1 1 1         1 1 1 1
    2 2 2 2         2 2 2 2
    3 3 3 3         4 4 4 4 
    4 4 4 4



 for example 

vector<vector<int>>vec;
    for i...//give vec values...
    vec[3].erase(vec.begin(),vec.end());

It seems like using vector.erase() or vector.clear() leaves an empty vector at the "third row"
Is there a way to completetly remove that vector so that

vec[3]=4 4 4 4

Thanx for a great forum...
/Bux

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满栀 2024-08-09 17:42:25

以下行删除 vec 的第三个元素。如果它有四个元素,则该行执行后将有三个。

vec.erase(vec.begin() + 2);

另一方面,下面的行将使第三个向量为空。

vec[2].clear();

The following line removes the third element of vec. If it had four elements, it will have three after the line is executed.

vec.erase(vec.begin() + 2);

The following line, on the other hand, will leave the third vector empty.

vec[2].clear();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文