插入浮点值2d向量时遇到麻烦 [英] Trouble in inserting float values 2d vectors
本文介绍了插入浮点值2d向量时遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector< vector< float > > v;
float x;
for(int i = 0;i < 3; i++)
{
for(int j = 0;j < 3 ; j++)
{
cin >> x;
v.push_back(x);
}
}
for(int i = 0;i < 3; i++)
{
for(int j = 0;j < 3; j++)
{
cout << v[i][j];
}
}
return 0;
}
我的尝试:
i已尝试上述代码,但显示错误:
没有匹配函数用于调用'std :: vector< std :: vector xmlns:std =#unknown> < INT> > :: push_back(int&)'
v.push_back(x);
What I have tried:
i have tried the above code but it shows error:
no matching function for call to 'std::vector<std::vector xmlns:std="#unknown"><int> >::push_back(int&)'
v.push_back(x);
推荐答案
你用它定义了一个向量向量
You defined a vector of vector with that
vector< vector< float > > v;
所以你需要取消引用它。
代码应该完成这项工作:
so you need to dereference it.
that code should do the job:
v[i].push_back(x);
这篇关于插入浮点值2d向量时遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文