小编Ste*_*ven的帖子

Eclipse CDT使用makefile.init,makefile.defs,makefile.targets生成makefile

我是CDT的新手,我正在尝试自动生成makefile.我注意到它包含三个根本不存在的文件,makefile.init,makefile.defs,makefile.targets.只是想知道,他们做了什么?他们为什么在那里?

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include objects.mk

#Other codes

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

#Other codes

-include ../makefile.targets
Run Code Online (Sandbox Code Playgroud)

eclipse-cdt

7
推荐指数
1
解决办法
3496
查看次数

如果通过指针分配,则c ++ vector.size()不会更新

只是想知道,有没有办法在使用指针更新向量时更新size()?考虑以下代码

std::vector<int> test;
test.reserve(5);
int* pt = test.data();
for (int i = 0; i < 5; ++i) {
    pt[i] = i;
}
for (int i = 0; i < 5; ++i) {
    printf("%d ? %d\n", pt[i], test[i]);
}
printf("Size:%zu Capacity:%zu Empty:%u\n", test.size(), test.capacity(), test.empty());
for (auto i : test) {
    printf("Nothing:%d\n", i);
}
printf("END\n");
Run Code Online (Sandbox Code Playgroud)

数字{0,1,2,3,4}分配给指针(pt),矢量(测试)占用这些值.输出是

0 ? 0
1 ? 1
2 ? 2
3 ? 3
4 ? 4
Size:0 Capacity:5 Empty:1
END
Run Code Online (Sandbox Code Playgroud)

大小保持为0,for循环不产生任何东西.我知道有很简单的方法可以解决这个问题,比如使用[]或push_back()分配给实际的向量.
但是,只是想知道,无论如何得到/更新正确的大小()?

编辑

也许有人指出使用 …

c++ vector c++11

0
推荐指数
1
解决办法
871
查看次数

标签 统计

c++ ×1

c++11 ×1

eclipse-cdt ×1

vector ×1