string/vector/iterator

本文详细介绍了C++标准库中string和vector容器的操作方法,包括常用成员函数如empty(), size(), push_back()等的使用方式及迭代器的概念与应用。

     // an iterator that cannot write elements
     vector<int>::const_iterator
     // an iterator whose value cannot change
     const vector<int>::iterator

Table 3.2. string Operations

s.empty()

Returns true if s is empty; otherwise returns false

s.size()

Returns number of characters in s

s[n]

Returns the character at position n in s; positions start at 0.

s1 + s2

Returns a string equal to the concatenation of s1 and s2

s1 = s2

Replaces characters in s1 by a copy of s2

v1 == v2

Returns true if v1 and v2 are equal; false otherwise

!=, <, <=,
>, and >=

Have their normal meanings


Table 3.5. vector Operations

v.empty()

Returns true if v is empty; otherwise returns false

v.size()

Returns number of elements in v

v.push_back(t)

Adds element with value t to end of v

v[n]

Returns element at position n in v

v1 = v2

Replaces elements in v1 by a copy of elements in v2

v1 == v2

Returns TRue if v1 and v2 are equal

!=, <, <=,
>, and >=

Have their normal meanings


//The iterator returned by begin refers to the first element, if any, in the container:
 vector<int>::iterator iter = ivec.begin();

//The iterator returned by the end operation is an iterator positioned "one past the end" of the vector.
 vector<int>::iterator iter = ivec.end();

 If the vector is empty, the iterator returned by begin is the same as the iterator returned by end.

from /usr/include/c++/9/bits/locale_classes.h:40, from /usr/include/c++/9/bits/ios_base.h:41, from /usr/include/c++/9/ios:42, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/eigen3/Eigen/Core:96, from /usr/include/eigen3/Eigen/StdVector:14, from /usr/include/pcl-1.10/pcl/point_cloud.h:45, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:1: /usr/include/c++/9/bits/stl_function.h:167:12: note: ‘std::plus’ 167 | struct plus : public binary_function<_Tp, _Tp, _Tp> | ^~~~ In file included from /usr/include/boost/mpl/aux_/include_preprocessed.hpp:37, from /usr/include/boost/mpl/aux_/arithmetic_op.hpp:34, from /usr/include/boost/mpl/plus.hpp:19, from /usr/include/boost/mpl/vector/aux_/iterator.hpp:19, from /usr/include/boost/mpl/vector/aux_/vector0.hpp:22, from /usr/include/boost/mpl/vector/aux_/clear.hpp:18, from /usr/include/boost/mpl/vector/vector0.hpp:24, from /usr/include/boost/mpl/vector/vector10.hpp:18, from /usr/include/boost/mpl/vector/vector20.hpp:18, from /usr/include/boost/mpl/vector.hpp:36, from /usr/include/pcl-1.10/pcl/register_point_struct.h:57, from /usr/include/pcl-1.10/pcl/point_types.h:44, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:2: /usr/include/boost/mpl/aux_/preprocessed/gcc/plus.hpp:68:8: note: ‘boost::mpl::plus’ 68 | struct plus | ^~~~ In file included from /usr/include/pcl-1.10/pcl/point_types.h:44, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:2: /usr/include/pcl-1.10/pcl/point_types.h: In function ‘const pcl::PrincipalRadiiRSD& pcl::common::operator+=(pcl::PrincipalRadiiRSD&, const float&)’: /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘plusscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘plusscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h: In function ‘const pcl::PrincipalRadiiRSD& pcl::common::operator-=(pcl::PrincipalRadiiRSD&, const pcl::PrincipalRadiiRSD&)’: /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘minus’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:541:1: note: suggested alternatives: In file included from /usr/include/c++/9/string:48, from /usr/include/c++/9/bits/locale_classes.h:40, from /usr/include/c++/9/bits/ios_base.h:41, from /usr/include/c++/9/ios:42, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/eigen3/Eigen/Core:96, from /usr/include/eigen3/Eigen/StdVector:14, from /usr/include/pcl-1.10/pcl/point_cloud.h:45, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:1: /usr/include/c++/9/bits/stl_function.h:177:12: note: ‘std::minus’ 177 | struct minus : public binary_function<_Tp, _Tp, _Tp> | ^~~~~ In file included from /usr/include/boost/mpl/aux_/include_preprocessed.hpp:37, from /usr/include/boost/mpl/aux_/arithmetic_op.hpp:34, from /usr/include/boost/mpl/minus.hpp:19, from /usr/include/boost/mpl/vector/aux_/iterator.hpp:20, from /usr/include/boost/mpl/vector/aux_/vector0.hpp:22, from /usr/include/boost/mpl/vector/aux_/clear.hpp:18, from /usr/include/boost/mpl/vector/vector0.hpp:24, from /usr/include/boost/mpl/vector/vector10.hpp:18, from /usr/include/boost/mpl/vector/vector20.hpp:18, from /usr/include/boost/mpl/vector.hpp:36, from /usr/include/pcl-1.10/pcl/register_point_struct.h:57, from /usr/include/pcl-1.10/pcl/point_types.h:44, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:2: /usr/include/boost/mpl/aux_/preprocessed/gcc/minus.hpp:68:8: note: ‘boost::mpl::minus’ 68 | struct minus | ^~~~~ In file included from /usr/include/pcl-1.10/pcl/point_types.h:44, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:2: /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘minus’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:541:1: note: suggested alternatives: In file included from /usr/include/c++/9/string:48, from /usr/include/c++/9/bits/locale_classes.h:40, from /usr/include/c++/9/bits/ios_base.h:41, from /usr/include/c++/9/ios:42, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/eigen3/Eigen/Core:96, from /usr/include/eigen3/Eigen/StdVector:14, from /usr/include/pcl-1.10/pcl/point_cloud.h:45, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:1: /usr/include/c++/9/bits/stl_function.h:177:12: note: ‘std::minus’ 177 | struct minus : public binary_function<_Tp, _Tp, _Tp> | ^~~~~ In file included from /usr/include/boost/mpl/aux_/include_preprocessed.hpp:37, from /usr/include/boost/mpl/aux_/arithmetic_op.hpp:34, from /usr/include/boost/mpl/minus.hpp:19, from /usr/include/boost/mpl/vector/aux_/iterator.hpp:20, from /usr/include/boost/mpl/vector/aux_/vector0.hpp:22, from /usr/include/boost/mpl/vector/aux_/clear.hpp:18, from /usr/include/boost/mpl/vector/vector0.hpp:24, from /usr/include/boost/mpl/vector/vector10.hpp:18, from /usr/include/boost/mpl/vector/vector20.hpp:18, from /usr/include/boost/mpl/vector.hpp:36, from /usr/include/pcl-1.10/pcl/register_point_struct.h:57, from /usr/include/pcl-1.10/pcl/point_types.h:44, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:2: /usr/include/boost/mpl/aux_/preprocessed/gcc/minus.hpp:68:8: note: ‘boost::mpl::minus’ 68 | struct minus | ^~~~~ In file included from /usr/include/pcl-1.10/pcl/point_types.h:44, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:2: /usr/include/pcl-1.10/pcl/point_types.h: In function ‘const pcl::PrincipalRadiiRSD& pcl::common::operator-=(pcl::PrincipalRadiiRSD&, const float&)’: /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘minusscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘minusscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h: In function ‘const pcl::PrincipalRadiiRSD& pcl::common::operator*=(pcl::PrincipalRadiiRSD&, const float&)’: /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘mulscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘mulscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h: In function ‘const pcl::PrincipalRadiiRSD& pcl::common::operator/=(pcl::PrincipalRadiiRSD&, const float&)’: /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘divscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:541:1: error: ‘divscalar’ is not a member of ‘pcl::traits’ 541 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PrincipalRadiiRSD, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h: At global scope: /usr/include/pcl-1.10/pcl/point_types.h:546:1: error: ‘type’ is not a member of ‘pcl::traits::datatype<pcl::Boundary, pcl::fields::boundary_point>::decomposed’ {aka ‘pcl::traits::decomposeArray<unsigned char>’} 546 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::Boundary, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:546:1: error: ‘type’ is not a member of ‘pcl::traits::datatype<pcl::Boundary, pcl::fields::boundary_point>::decomposed’ {aka ‘pcl::traits::decomposeArray<unsigned char>’} /usr/include/pcl-1.10/pcl/point_types.h:546:1: error: template argument 1 is invalid 546 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::Boundary, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h: In function ‘const pcl::Boundary& pcl::common::operator+=(pcl::Boundary&, const pcl::Boundary&)’: /usr/include/pcl-1.10/pcl/point_types.h:546:1: error: ‘plus’ is not a member of ‘pcl::traits’ 546 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::Boundary, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:546:1: note: suggested alternatives: In file included from /usr/include/c++/9/string:48, from /usr/include/c++/9/bits/locale_classes.h:40, from /usr/include/c++/9/bits/ios_base.h:41, from /usr/include/c++/9/ios:42, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/eigen3/Eigen/Core:96, from /usr/include/eigen3/Eigen/StdVector:14, from /usr/include/pcl-1.10/pcl/point_cloud.h:45, from /home/annant/competition_ws/src/Fast-Planner/uav_simulator/map_generator/src/random_forest_sensing.cpp:1: /usr/include/c++/9/bits/stl_function.h:167:12: note: ‘std::plus’ 167 | struct plus : public binary_function<_Tp, _Tp, _Tp> | ^~~~ In file included from /usr/include/boost/mpl/aux_/include_preprocessed.hpp:37, from /usr/include/boost/mpl/aux_/arithmetic_op.hpp:34, from /usr/include/boost/mpl/plus.hpp:19, from /usr/include/boost/mpl/vector/aux_/iterator.hpp:19, from /usr/include/boost/mpl/vector/aux_/vector0.hpp:22, from /usr/include/boost/mpl/vector/aux_/clear.hpp:18, from /usr/include/boost/mpl/vector/vector0.hpp:24, from /usr/include/boost/mpl/vector/vector10.hpp:18, from /usr/include/boost/mpl/vector/vector20.hpp:18, from /usr/include/boost/mpl/vector.hpp:36, from /usr/include/pcl-1.10/pcl/register_point_struct.h:57,
最新发布
09-05
### 问题分析 在编译 `random_forest_sensing.cpp` 文件时出现 `‘plusscalar’`、`‘minus’` 等不是 `‘pcl::traits’` 成员,以及 `‘type’` 不是 `‘pcl::traits::datatype<pcl::Boundary, pcl::fields::boundary_point>::decomposed’` 成员的错误,这些错误通常是由于 PCL(点云库)版本不兼容或者头文件包含问题导致的。 ### 解决方案 #### 1. 检查 PCL 版本 确保使用的 PCL 版本与代码兼容。不同版本的 PCL 可能会有 API 的变化,某些成员函数或类型可能在不同版本中有所不同。可以通过以下命令查看当前安装的 PCL 版本: ```bash dpkg -s libpcl-dev | grep Version ``` 如果版本不兼容,可以尝试升级或降级 PCL 版本。例如,在 Ubuntu 上,可以使用以下命令安装指定版本的 PCL: ```bash sudo apt-get install libpcl-dev=1.8.1-* ``` #### 2. 检查头文件包含 确保代码中包含了正确的 PCL 头文件。不同的 PCL 功能需要包含不同的头文件,缺少必要的头文件可能会导致编译器找不到相应的成员。在 `random_forest_sensing.cpp` 文件中,确保包含了与 `pcl::traits` 相关的头文件,例如: ```cpp #include <pcl/point_types.h> #include <pcl/traits.h> ``` #### 3. 检查命名空间 确保代码中正确使用了 PCL 的命名空间。如果没有正确使用命名空间,编译器可能无法找到 `pcl::traits` 及其成员。可以在代码中使用 `using` 语句或者显式指定命名空间: ```cpp using namespace pcl; // 或者 pcl::traits::... ``` #### 4. 检查代码逻辑 检查代码中是否存在拼写错误或者错误的使用方式。确保在使用 `pcl::traits` 的成员时,参数和调用方式是正确的。例如,检查 `pcl::traits::datatype<pcl::Boundary, pcl::fields::boundary_point>::decomposed` 的使用是否符合 PCL 的 API 文档。 ### 示例代码 以下是一个简单的示例,展示了如何正确包含 PCL 头文件和使用命名空间: ```cpp #include <iostream> #include <pcl/point_types.h> #include <pcl/traits.h> int main() { // 使用 pcl::traits 的示例 pcl::PointXYZ point; // 这里只是示例,具体使用根据实际需求 // pcl::traits::... return 0; } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值