Here I have a vector of "nice" structs, each with a simple int member. All i want to do is for each element in the vector change the struct member to 5, but i cant seem to get it to behave properly. i tried at first passing the vector by address but the struct members didnt update. Here i tried using a pointer vector but the program crashes and i cant figure out why that is either
Ive been playing with this for several days but cant figure it out, any help would be appreciated.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct nice{
nice(int val):v(val){}
int v;
};
void remo(vector<nice>* h){
for(nice g:*h){
g.v=5;
}
}
int main(){
vector<nice> *vec;
for(int i=0;i<7;i++){
nice n(i+1);
vec->push_back(n);
}
for(nice d:*vec){
cout<<d.v<<" ";
}
cout<<endl;
remo(vec);
for(nice d:*vec){
cout<<d.v<<" ";
}
}