reading from a file into vectors

Hello guys;

How can i create a function in C++ that reads into three dynamically (not statically sized) sized vectors?.I have been searching the web for hours and I couldn't find any good example.
my file contains the following values:

1234 25 19.99

1238 67 9.99

2345 47 29.99

2347 4 19.99

how can i read those values into three vectors???

thank u for ur help in advanced.
read the variables normally into a non-vector int/double/whatever

push_back the value into the vector so it grows dynamically
Im using this, but it just get the first values which is 1234.
I haven't even tried to values into the other vectors.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include<fstream>
#include <vector>
using namespace std;


int main()
{
	ifstream inFile;
	inFile.open("c:\\values.txt");

   vector<int> product_id;
   vector<int> qty;
   vector<int> price;
 
   // Store values in the vector.
   while(!inFile.eof())
   {
	   int product_idc;
	   inFile >> product_idc ;
	   product_id.push_back(product_idc);
	   



	   for (int i = 0; i < product_id.size(); i++) 
        { 
            cout << "Values: " << (i+1) << product_id[i]; 
        } 
	   
	inFile.close();
   }
    





   system("pause");
  
   return 0;
}
Um, line 31 closes the file. So you can't read anymore from it.

Further more you can't read past the end of the line with inFile >> .... You need std::getline(inFile, line);. Pass that 'line' to a stringstream and read the values from that stringstream
Topic archived. No new replies allowed.