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
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
ifstream inf("foo.txt");
int numNodes;
inf >> numNodes;
for ( int i = 0 ; i < numNodes ; i++ ) {
int nodeNum, left, right;
char data;
while ( inf >> nodeNum >> ws >> data >> left >> right ) {
cout << "N=" << nodeNum
<< ", C=" << data
<< ", L=" << left
<< ", R=" << right
<< endl;
}
}
return 0;
}
$ g++ foo.cpp
$ ./a.out
N=1, C=e, L=0, R=0
N=2, C=z, L=0, R=0
N=3, C=e, L=1, R=2
N=4, C=i, L=0, R=0
N=5, C=e, L=0, R=0
N=6, C=h, L=0, R=0
N=7, C=a, L=3, R=4
N=8, C=w, L=5, R=6
N=9, C=f, L=7, R=8
|