Read int from a file, delimited by "\"

I am trying to read ints from my file, they are delimited from each other by slashes. Here is my code so far:
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
int main()
{
    int A = 0, B = 0, C = 0, validCount = 0;
    ifstream input;
    input.open("date.dat");
    Date allPossible[6], allValid[6];
    input >> A;
    input >> B;
    input >> C;
    allPossible[0].set(A, B, C);
    allPossible[1].set(A, C, B);
    allPossible[2].set(B, A, C);
    allPossible[3].set(B, C, A);
    allPossible[4].set(C, B, A);
    allPossible[5].set(C, A, B);
    for(int index = 0; index <= 5; index++)
    {
            if(allPossible[index].checkValidity())
            {
                                            allValid[validCount] = allPossible[index];
                                            validCount++;
            }
    }
    for(int index = 0; index <= validCount; index++)
    {
            cout << allValid[index].getDay() << "/" << allValid[index].getMonth() << "/" << allValid[index].getYear() << endl;
    }
    system("Pause");
}
    


I am feeding it this:
02/4/67

It's not reading anything! I'm totally a novice, so all help is appreciated.
1
2
3
4
5
6
7
std::ifstream file( "date.dat" ) ;
int number ;
char delimiter ;
while( ( file >> number >> delimiter ) && ( delimiter == '/' ) )
{
    // use number which has been read 
}

you can also use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int A[3] = {0};
ifstream input;
string Line;

for (int i = 0; i < 3 ; i++) // get 3 values
{
    getline(input,Line,'/'); // get values, one at a time, delimited by the / character
    stringstream iss; 
    iss << Line; //Put the string into a stream
    iss >> A[i]; //This outputs the data as an int.
} 

allPossible[0].set(A[0], A[1], A[2]);
...


Edit: This requires the following libraries:
1
2
#include <fstream>
#include <sstream> 
Last edited on
I tried this, and it's still not reading anything.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    while( ( input >> A >> delimiter ) && ( delimiter == '/' ) )
    {
           while( ( input >> B >> delimiter ) && ( delimiter == '/' ) )
           {
                  while( (input >> C >> delimiter) && ( delimiter == '/') )
                  {
                         allPossible[0].set(A, B, C);
                         allPossible[1].set(A, C, B);
                         allPossible[2].set(B, A, C);
                         allPossible[3].set(B, C, A);
                         allPossible[4].set(C, B, A);
                         allPossible[5].set(C, A, B);
                  }
           }
    }
Last edited on
@Stewbond
Thanks! It worked!
Topic archived. No new replies allowed.