1. 程式人生 > >c++根據檔名讀取.txt檔案

c++根據檔名讀取.txt檔案

新手程式碼如下:

#include<iostream>

#include<fstream>
#include<string>
using namespace std;
int main(){
string filename = "";  
cin>>filename;   //輸入檔名
ifstream file(filename.c_str()); 
char buffer[16384];
while(!file.eof()){
file.getline(buffer,16383);
cout<<buffer<<endl;
}
cin.get();
cin.get();
return 0;
}