R
Roman Töngi
I want to change a vector in a function. I pass a pointer of it to
the function and append an item. Then I want to print the first
item in the vector. It doesn't work. Can anyone help me?
Thanks
#include <vector>
#include <iostream>
#include "element.h"
using namespace std;
void element(vector<int>*);
int main()
{
vector<int> vecval;
element(vecval);
cout << vecval[0];
cin.ignore();
return 0;
}
//header element.h
#pragma once
#include <vector>
using namespace std;
void element(vector<int>* pval)
{
pval->push_back(5);
return;
}
the function and append an item. Then I want to print the first
item in the vector. It doesn't work. Can anyone help me?
Thanks
#include <vector>
#include <iostream>
#include "element.h"
using namespace std;
void element(vector<int>*);
int main()
{
vector<int> vecval;
element(vecval);
cout << vecval[0];
cin.ignore();
return 0;
}
//header element.h
#pragma once
#include <vector>
using namespace std;
void element(vector<int>* pval)
{
pval->push_back(5);
return;
}