I have a data that looks like this:
AAA 0.3 1.00 foo chr1,100
AAC 0.1 2.00 bar chr2,33
AAT 3.3 2.11 chr3,45
AAG 1.3 3.11 qux chr1,88
ACA 2.3 1.33 chr8,13
ACT 2.3 7.00 bux chr5,122
Note that the lines above are tab separated. Moreover, it sometime may contain 5 fields or 4 fields.
What I want to do is to capture 4th fields in variable as "" if it doesn't contain any value.
I have the following codes, but somehow it reads the 5th fields, as 4th fields when 4th is empty.
What's the correct way to do it?
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
int main ( int arg_count, char *arg_vec[] ) {
string line;
ifstream myfile (arg_vec[1]);
if (myfile.is_open())
{
while (getline(myfile,line) )
{
stringstream ss(line);
string Tag;
double Val1;
double Val2;
double Field4;
double Field5;
ss >> Tag >> Val1 >> Val2 >> Field4 >> Field5;
cout << Field4 << endl;
//cout << Tag << "," << Val1 << "," << Val2 << "," << Field4 << "," << Field5 << endl;
}
myfile.close();
}
else { cout << "Unable to open file"; }
return 0;
}