![]() ![]() The fopen() method accepts two arguments, the first argument is a character array denoting the filename and the second argument is the parameter indicating the mode of opening the file. For this, we can open a file using the fopen() method and store the file pointer to a FILE pointer object. We can use C-style file handling to read the file and count the number of lines in it. There is an alternative way to count the number of lines in a file in C++. How To Count Lines In A File In C++ Using C-style Approach? Until we reach the end of the file, we read the file line by line and increase the count. Here we check if the next character to be read is the EOF (end of file) character or not, using the peek() method. ![]()
0 Comments
Leave a Reply. |