Nov 17, 2011 at 10:01pm UTC
Hey,
I am currently working on a code to analyze my raw data
DH 0 26 64
0xe91a41
DH 0 26 65
0xe91a42
DH 0 26 66
0xe91a43
DH 0 26 67
0xe91a44
DH 0 26 68
0x04330f
DR 2 51 0
0x043b1f
DR 2 59 1
and I understand how to input my raw data file and output a file but I am having trouble with the while loop. I would like to only read the DH lines and write them to the output file, for example:
the output file should look like this:
DH 0 26 64
DH 0 26 65
DH 0 26 66
DH 0 26 67
DH 0 26 68
what would my while loop look like?
Thank you
Nov 17, 2011 at 10:36pm UTC
Can someone please help me because I am really having difficulty with getting exactly what they output should look like?
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
void Source16()
{
char inputFilename[] = "DH.txt";
char outputFilename[] = "outDH.txt";
ifstream inFile;
ofstream outFile;
char DH[3]; // One extra for null char.
int flag, LVL1, BCID;
inFile.open(inputFilename, ios::in);
if (!inFile) {
cerr << "Can't open input file " << inputFilename << endl;
exit(1);
}
outFile.open(outputFilename, ios::out);
if (!outFile) {
cerr << "Can't open output file " << outputFilename << endl;
exit(1);
}
while (inFile >> DH >> flag >> LVL1 >> BCID ) {
outFile << DH << " " << flag<< " " << LVL1 << " " << BCID <<endl;
}
inFile.close();
outFile.close();
return 0;
}