c++ 结构体容器(vector)类型初始化及结构体vector指针传递

2021-09-15 11:39:18 浏览数 (1)

代码语言:c复制
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <vector>
 4 
 5 
 6 struct BoxInfo
 7 {
 8     int label;
 9     float score;
10 };
11 
12 
13 int bbox_init(std::vector<BoxInfo> &bboxs)
14 {
15     BoxInfo u_temp;
16     for(int i = 0; i < 10; i  )
17     {
18         u_temp.score = 0.8f  0.1f*i;
19         u_temp.label = i;
20 
21         bboxs.push_back(u_temp);
22     }
23 
24     return 0;
25 }
26 
27 
28 int main()
29 {
30     printf("begin rn");
31     std::vector<BoxInfo> bboxs;
32 
33     bbox_init(bboxs);
34 
35     printf("mid rn");
36 
37     for(int i = 0; i < 10; i  )
38     {
39         printf("bboxs[%d].score = %f rn",i,bboxs[i].score);
40         printf("bboxs[%d].label = %d rn",i,bboxs[i].label);
41     }
42     printf("bboxs.size() = %d rn",bboxs.size());
43 }

0 人点赞