reading integers from a txt file

my txt file looks like this:

36 6 19
15 11 7
41 8 40
9 11 3
23 22 1     
30 12 13
0 0 0

and its called testfile.txt
using codeblocks, i am trying to read the numbers into 3 different int variables called totalPeople, drinkingInterval, and yourPosition in that order. so far this is what i have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<fstream>

using namespace std;

int totalPeople;
int drinkingInterval;
int yourPosition;
int main () {
    ifstream indata;
    indata.open (testfile.txt)


indata>>totalPeople>>drinkingInterval>>yourPosition;
cout<<totalpeople;
}


What am i doing wrong? im not even sure if its opening the txt file..

~note. thats not the entire code, just what i found relevant. its part of a much larger program.

im putting this in a loop to read the rest of the data, right now im trying to read row one.
Last edited on
You must have a string as filene:indata.open ("testfile.txt");
nvm, i figured it out=]
Topic archived. No new replies allowed.