2021-08-15

本周注意点:

一.关于ros
(1)rosrun 运行的是 功能包+节点名;
rosservice rostopic 直接指定话题或者服务;

(2)消息发布器在一个while里面一直循环发送“hello world”到话题(topic)chatter上。消息订阅器一旦知道chatter上面有data,就会将这data作为参数传入callback函数中,但是此时还没有执行callback函数,而是把callback函数放到了一个回调函数队列中。所以当发布器不断发送data到chatter上面时,就会有相应的callback函数进入队列中,它们函数名一样,只是实参不一样。
原文链接:https://blog.csdn.net/liweibin1994/article/details/53084306
ros::spin(); //死循环,程序跑不出去了(无回调函数不占CPU),一直等待回调函数,并执行,阻塞程序
ros::spinOnce(); 执行一个等待队列中的回调函数

(3)std::msgs支持的类型
原文链接:https://blog.csdn.net/xuan196/article/details/108359686
在这里插入图片描述

二.关于c++字符串(参考链接:http://c.biancheng.net/view/1527.html)
数字与字符串转换问题,拼接问题:

头文件:#include

C++ 有两个类,ostringstream 和 istringstream,可以用来对内存中的值执行字符串/数字转换。

ostringstream 类是 ostream 的子类(cout 也属于该类),并使用流插入运算符 << 将数值转换为字符串。ostringstream 类型对象的工作方式与cout和文件对象的工作方式相同,但它不是将数据写入屏幕或文件,而是写入它所包含的字符串对象中。
每次在 ostringstream 对象上使用 << 时,它都会执行必要的数字到字符串的转换,并将结果追加到其字符串的末尾。除了支持 ostream 类的所有成员函数和运算符外,ostringstream 对象还支持表 1 中所示的 str 成员函数。

istringstream 类是从 istream 派生的。它内部包含一个字符串对象,函数将它作为可以从中"读取"的输入流。

用法:

#include <sstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str = "John 20 50"; // string to read from
    const char *cstr = "Amy 30 42"; // Cstring to read from
    istringstream istr1 (str);    **// istr1 will read from str**
    istringstream istr2; // istr2 will read from cstr
    ostringstream ostr; // The ostringstream object to write to
    string name;
    int score1, score2, average_score;
    // Read name and scores and compute average then write to ostr
    istr1 >> name >> score1 >> score2;
    average_score = (score1 + score2)/2;
    ostr << name << " has average score" << average_score << "\n";
    // Set istr2 to read from the C string and repeat the above
    istr2.str(cstr);
    istr2 >> name >> score1 >> score2;
    average_score = (score1 + score2)/2;
    ostr << name << " has average score" << average_score << "\n";
    // Switch to hexadeximal output on ostr
    ostr << hex;
    // Write Amy's scores in hexadecimal
    ostr << name << "'s scores in hexadecimal are: " << score1 << " and " << score2 << "\n";
    // Extract the string from ostr and print it to the screen
    cout << ostr.str();
    return 0;
}

典型用法:
istringstream istr1 (str);
istr1 >> name >> score1 >> score2;
ostringstream ostr;
ostr << name << " has average score" << average_score << “\n”

(4)ubuntu录屏软件:kazam,搜索打开即可使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值