C ++矢量充满了矢量问题

时间:2015-10-15 19:30:26

标签: c++ vector

我正在尝试编写一个程序,对三对角矩阵进行一些研究生水平的数值分析。

我很确定我有数据输入,我无法弄清楚是为什么代码 vector <vector <double>> x;正在回击圣经比例的错误。

代码如下:

#include <iostream> 
#include <vector>
#include <cstdlib>
#include <iterator>
#include <iomanip>
using namespace std;

int main()
{
    int i, j;
    double y;
    vector< vector< double > > x(10);

    //Stuff data packets
    for (i = 0; i < 9; i++)
    {
        cin >> y;
        x.push_back(y);
    }
    //display
    for (j = 0; j < 9; j++)
    {
        cout << x[j] << setw(5);
    }
    cout << endl;
    cout << x.size(); //Making sure it's right size
    return 0;
}

如何在C ++中制作一个充满向量的向量!?

2 个答案:

答案 0 :(得分:4)

向量x包含std::vector<double>类型的元素,而y类型为double。这就是为什么你不能push_backy的值x转换为Private Sub TreeView1_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterCheck If e.Action <> TreeViewAction.ByMouse And e.Action <> TreeViewAction.ByKeyboard Then Exit Sub Dim CheckedNode As TreeNode = e.Node Dim CheckedNodeIsRoot As Boolean = CheckedNode.Parent Is Nothing Dim ParentNode As TreeNode = CheckedNode.Parent Dim ChildOneUnchecked As Boolean = False If CheckedNodeIsRoot Then For Each ChildNode As TreeNode In CheckedNode.Nodes ChildNode.Checked = CheckedNode.Checked Next Else If CheckedNode.Checked Then For Each ChildNode As TreeNode In ParentNode.Nodes If Not ChildNode.Checked Then ChildOneUnchecked = True Next If ChildOneUnchecked Then ParentNode.Checked = False Else ParentNode.Checked = True End If Else ParentNode.Checked = False End If End If End Sub

答案 1 :(得分:2)

由于xvector<vector<double>>x.push_back(y);需要vector<double>,但y只是double

您需要将y添加到vector<double>,然后将其添加到x或将x添加到vector<double>