I'm trying to understand this stringstream function stringstream ss(line);
not quite sure what it's purpose is or what it does.
I'm really new to C++ so I'm sorry if this really simple and stupid. Anything helps thanks!
c++
float process(float Beta, std::ifstream & INPUT, float mass, float energy, int Juse = 1, int Jerror = 1, int intype = 1)
{
float crosscons = 8 * M_PI * mass * mass / energy; //Creates a constant that is used to calculate the cross section
int dwarf_count = 0;
int dcol = 0;
string line;
string item;
int header = 0;
string skip("#");
INPUT.seekg(0, ios::beg);
while (getline(INPUT, line))
{
if (contains(line, skip))
{
header++;
} else {
break;
}
}
INPUT.seekg(0, ios::beg); // same as above, searching for the INPUT i.e File.
for (int i = 0; i < header; ++i)
{
getline(INPUT, line);
}
while (getline(INPUT, line))
{
++dwarf_count;
if (dwarf_count == 1)
{
stringstream ss(line);
while (ss >> item)
dcol++; // creates a variable in the while loop, that probably means column
}
}
question from:
https://stackoverflow.com/questions/65950443/understanding-a-function-stringstream 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…