I am trying to iterate through my vector array, but I cannot seem to get it to work, my error is at the second for loop and the error message is the follow:
expected primary expression before 'double'
I have looked through on how to iterate a regular vector, but how do I iterator a vector array? I followed this structure:
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector;
for (int i=1; i<=5; i++) myvector.push_back(i);
std::cout << "myvector contains:";
for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
I can't seem to get my vector array version to work.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(int arc, char *argv[])
{
vector<double> vector[7];
double num[7];
ifstream infile("data.txt");
string temp;
for(int i = 0; i <= 6; i++)
{
infile >> temp;
cout << temp << ' ';
}
cout << endl;
while(infile >> num[0] >> num[1] >> num[2] >> num[3] >> num[4] >> num[5] >> num[6])
{
for(int i = 0; i <= 6; i++)
{
vector[i].push_back(num[i]);
}
}
cout << endl;
for(int i = 0; i <= 6; i++)
{
// error on this line
// not sure what is wrong before vector<double>:: iterator it = vector[i].begin()
for(vector<double>::iterator it = vector[i].begin(); it != vector[i].end(); ++it)
{
cout << ' ' << *it;
}
}
return 0;
}
vector<double> my_vector[7];Try to avoidusing namespace stdto prevent this from happening.for(double d:v)//stuff;ftw