This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include<cstdlib> | |
#include<fstream> | |
using namespace std; | |
int main() | |
{ | |
ifstream fin; | |
int line = 0; | |
string tmps; | |
fin.open("file.in",ios::in);//開檔讀取 | |
while(getline (fin,tmps)){ | |
line++;//一行一行讀,每讀一行就加一 | |
} | |
fin.close();//關閉文件 | |
cout << line << endl;//輸出行數 | |
return 0; | |
} |
參考資料:
Stack Overflow Reading a text file - fopen vs. ifstream