Hello all, I am fairly new to C++ programming and have been struggling immensely with a program I am trying to write. Basically I have a document with words and numbers and I am trying to sift out only the numerical data from the file and output just the numerical data to a separate file. I have tried literally everything from stringstreams to buffers, yet my ouptut is not what I want... Here is the program I developed:
int main()
{
double a, b, c, d, e;
char type[100];
std::fstream ss;
std::ifstream in("data.txt", ios::in);
ss << in.rdbuf();
ofstream out("numbers", ios::out | ios::trunc);
ss >> type >> a >> type >> type >> type >> type >> b >> c >> d >> e;
out << a << " " << b << " " << c << " " << " " << d << " " << e;
in.close();
out.close();
return 0;
}
The following is the file input:
Run 141544 event 5Njets 0m1: pt,eta,phi,m= 231.277 0.496237 -2.22082 0.1
However, instead of isolating the numbers above, I get the output file:
2.01522e-307 8.38576e+266 7.85045e-307 1.91463e-302 -1.89701e-218
Can some please point me int he right direction? I have been banging my head on this for two days now. Again, I apologize because I am very new to C++.
Thank you for the post, but mmmm... still not working, it still gives still gives me a random out put of numbers:
141544 3.63308e-317 3.47556e-308 1.44224e-306 1.97626e-323
for some reason though the first number prints, but none of the next in the input series:
Run 141544 event 5Njets 0m1: pt,eta,phi,m= 231.277 0.496237 -2.22082 0.1