Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

trying to understand C++ code, reading a file

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;
        }
    }

This first bit I know it's reading a file, but I have no idea where it's reading the file or where it gets it from. Inside the function I know it's trying to skip to the data because it looks like the file is filled with # I'm really new to C++ so i'm sorry if this really simple and stupid. Anything helps thanks!

question from:https://stackoverflow.com/questions/65894960/trying-to-understand-c-code-reading-a-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have no idea where it's reading the file

The call to INPUT.seekg() is seeking the INPUT stream's read pointer to the beginning of the file, and then the getline() loop is reading individual lines of text from the stream until the end of the stream is reached, or a line not containing # is found, whichever occurs first.

or where it gets it from

The process() is getting the INPUT stream from the caller as an input parameter. Where the caller is getting the stream from, we can't answer that, as there is not enough code shown. You need to look at the code that is calling process() to know where the INPUT stream is coming from.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...