Reputation: 89
I'm having some problems reading a vector of ints from a file... and it's the first time this happens to me and I have tried everything. Here is a part of my code:
#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
int m;
std::vector<int>a[100];
std::vector<int>b[100];
int main()
{
std::ifstream file("data.in");
file>>m;
int i;
for( i = 0; i<m/2; i++ )
file>>a[i]>>b[i];
return 0;
}
Why won't it work? :(
Upvotes: 0
Views: 251
Reputation: 119164
std::vector<int>a[100];
declares an array containing 100 vectors. So a[i]
is a vector, not an int
. You can't read a vector directly from input.
If you want vectors of size 100, instead of an array of 100 vectors, the syntax is
std::vector<int> a(100);
Upvotes: 4