C++网格阵列矢量ostream

C++ mesh array vector ostream

本文关键字:ostream 阵列 网格 C++      更新时间:2023-10-16

我在故障排除方面遇到了极大的困难,如果有任何建议,我将不胜感激。1.我正在尝试创建一个网格阵列。这应该会生成一个50、52、54、56…100的向量。在调试过程中,我从未看到矢量增加超过50。2.我正在尝试打印网格阵列。我不能在这里使用ostream,因为这不是一个类。所以即使我能让矢量工作,我也不知道如何打印它

#include <vector>
#include <iostream>
using namespace std;
vector<double> MeshArray(double start, double end, double h)
{
    vector<double> mesh;
    mesh.reserve(100);
    for (double i = start; i <= end; i + h)
        mesh.push_back(i);
    return mesh;
}
int main()
{
    vector<double> MA = MeshArray(50,100,2);
    cout << MA;
    return 0;
}
#include<iostream>
#include"Header.h"
#include<cstdlib>
using namespace std;
int main()
{
    vector<double> MA = MeshArray(50, 100, 2);
    int size = MA.size();
    for (int i = 0; i < size; i++)
        cout << MA[i] << endl;
    system("Pause");
    return 0;
}
#include<vector>
#include<iostream>
using namespace std;
vector<double> MeshArray(double start, double end, double h)
{
    vector<double> mesh;
    mesh.reserve(100);
    for (double i = start; i <= end; i += h)
        mesh.push_back(i);
    return mesh;
}