Q: Having trouble understanding C++ streams I have to read some data from an input stream, run it through some filters, and then display the context on screen. I'm working with Windows and currently stuck on this. I'm having a hard time understanding the I/O streams.
I don't know what I should do after passing the data through the first filter because currently, the second function calculates 0 chars?
main:
std::ifstream data("somedata.txt");
whitesprem(data);
calc_chars(data);

whitesprem:
    // removes extra white spaces

    void whitesprem(std::ifstream& fff) {
        std::string line;

        while(std::getline(fff, line)){
          std::regex rgx("\\s{2,}");
          line = std::regex_replace(line, rgx, " ")
          //How to move on?
       }    
   }


A: I'd consume each line inside your whiteprem(). Another approach could be to just copy the data to another string stream from the file stream and use the new stream in the rest of the program.
Probably you intend to do something like this:

void whiteprem(std::ifstream& ff, std::stringstream &update){
std::string line;

        while(std::getline(fff, line)){
          std::regex rgx("\\s{2,}");
          line = std::regex_replace(line, rgx, " ")
          //How to move on?
          update << line << std::endl;
       }

}
int main(){
  std::ifstream data("somedata.txt");
  std::stringstream ss;
  whitesprem(data, ss);
  calc_chars(ss);
}


