- #include<iostream>
- #include<fstream>
- using namespace std;
- ifstream ifs;
- string str;
- int main()
- {
- ifs.open("read.txt");
- while(getline(ifs, str)) //包含空白逐行讀取
- cout<<str<<endl;
- /*
- getline(ifs, str); //逐行讀取原理
- cout<<str<<endl;
- getline(ifs, str);
- cout<<str<<endl;
- */
- return 0;
- }
複製代碼 |