#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool OpenFile(fstream &file, char *name);
void ShowContents(fstream &file);
int main()
{
fstream dataFile;
if(!OpenFile(dataFile, "demo.txt"))
{
cout << "Error !" << endl;
return 0;
}
cout << "Successfully.\n";
ShowContents(dataFile);
dataFile.close();
return 0;
}
bool OpenFile(fstream &file, char *name)
{
file.open(name, ios::in);
if(file.fail())
return false;
else
return true;
}
void ShowContents(fstream &file)
{ > clude
> inclu
string line;
while(getline(file, line)){
cout << line << endl;
}
Tại sao phải truyền tham chiếu ở dòng bool vậy và làm sao phải char *name vậy. Ai Giải đáp giúp e!