简体   繁体   中英

C++ mesh array vector ostream

I'm having extreme difficulty troubleshooting this, I'd be grateful for any advice. 1. I am trying to create a mesh array. This should generate a vector of 50, 52, 54 56...100. In debugging I never see the vector increase beyond 50. 2. I am trying to print the mesh array. I cannot use ostream here because this is not a class. So even if I could get the vector working, I don't know how to print it.

#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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM