打印std::vector<uint8_t> 和 std::vector<std::string> 变量
时间: 2024-07-03 22:00:28 浏览: 10
在C++中,打印`std::vector<uint8_t>`和`std::vector<std::string>`变量通常涉及到迭代并打印每个元素。这里是一个例子:
```cpp
#include <iostream>
#include <vector>
// 假设你有一个vector<uint8_t>
std::vector<uint8_t> byteVector = {1, 2, 3, 4, 5};
// 假设你有一个vector<std::string>
std::vector<std::string> stringVector = {"Hello", "World"};
// 打印uint8_t vector
std::cout << "Byte Vector:\n";
for (const auto& byte : byteVector) {
std::cout << static_cast<int>(byte) << " ";
}
std::cout << "\n";
// 打印string vector
std::cout << "String Vector:\n";
for (const auto& str : stringVector) {
std::cout << str << " ";
}
std::cout << "\n";
```
在这个例子中,我们遍历`std::vector<uint8_t>`并将其转换为整数(因为`uint8_t`通常表示单个字节),然后对`std::vector<std::string>`直接打印字符串。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)