-4

They ask us to implement a function that reads from the second line of text file CSV as follows:

PRE: The flow «f» is associated with a text file with the format of uses of the Bizi system established in the statement and in the disposition of read from the beginning of a line other than the header.
Post: You have tried to read the line mentioned in the precondition and, if you have not finished the data of the file in that attempt, you have stored in the fields of the parameter "use" the user's identifier to which corresponds the use of the read line and the codes of the bicycle removal and return stations.

void leerUso(istream& f, UsoBizi& uso) {}

Please can some one help me to understand How I can read from second line of text file that separate by (;) and extract parameter, with example?

cse
  • 4,066
  • 2
  • 20
  • 37
Thaer
  • 1
  • 2

1 Answers1

0

You have to iterate through your file until the end is reached as follows:

#include <iostream>
#include <fstream>
#include <string>

int main()
{
    std::string line;

    std::ifstream arq("/tmp/blah");

    if (arq.is_open()){

        while (!arq.eof()) {

            std::getline(arq, line);

            std::cout << line << std::endl; // prints the line you've just read
        }
    }
}

The values can be retrieved from the string by tokenizing it just like in this post, and then converted to double as explained here.