I posted this last time but I am hoping I can get some more input. This seems like a pretty easy task to implement but I can't figure out the best way of doing it. I have some data that looks like the following:
The first entries of each line tell you what kind of particle you are dealing with and the next four entries are energy, x-position, y-position and z-position respectively. I process this data with the getline function:
1 2 3 4 5
ifstream myfile("C:\\file.txt");
while (myfile.good())
{
getline(myfile, line);
}
Next I need to extract the energy and x, y and z positions from each line so that that you would be able to write the parameters from each line like:
You are very likely clobbering memory you shouldn't be. The %s in the format string tells sscan f to interpret the memory pointed to by &plus and &particle as c strings; as you've defined them, they are single characters. particle looks like it actually should be a string.
You might want to try a more c++esque approach:
#include <sstream>
float x, y, z, energy ;
char plus ;
string particle ;