如何打印矢量的数据

2023-07-02C/C++开发问题
6

本文介绍了如何打印矢量的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在互联网上搜索了很多,但找不到打印矢量数据的简单示例..

I've searched a lot over the internet, and couldent find simple examples to print vector's data..

我试图像数组一样打印它,但它没有用...

I tried to print it like an array, though it didnt worked...

这是我尝试过的:

using namespace std ;
.....
const int MAX = 255 ;

vector <string> testersName[MAX];
cout << testersName[i] << endl;

错误仅在 cout 行中,第一行正在得到遵守,一切顺利..

The error is only in the cout line, the first line is getting complied and everything goes well..

我在 testersName 中得到了数据,但我收到了这个错误:

I got data inside testersName, though Im getting this error :

"错误 1 错误 C2679: 二进制 '<<': 没有找到使用std::vector<_Ty>"类型的右侧操作数的运算符(或者没有可接受的转换)"

"Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)"

推荐答案

vector testersName[MAX]; 声明了一个向量数组,尝试简单的 vector ;testersName(MAX); - 这声明了一个带有 MAX 元素的向量.

vector <string> testersName[MAX]; declares an array of vectors, try simply vector <string> testersName(MAX); - this declares a vector with MAX elements.

这篇关于如何打印矢量的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6