help for reading from text file !!!!

I have to write a function which reads from a file and allocate it . if it is binary file open for binary or if it is text file function must open it in that way

my question is

void readPlayerInfosFromFile(fstream *file , string fileType )

when I declare that function I don't understand meaning of fstream *file

What is the function of this parameter fstream * file
You used it as a function parameter before you knew what it does? O_o ... wat.

Read the tutorial on file I/O http://cplusplus.com/doc/tutorial/files/
Last edited on
But there is no information about how to use streams as a parameter of function ?
use a char, it works as well. For example:
1
2
3
4
5
void /*function name*/(char filename){
fstream filereader;
filereader.open(filename);
//rest of the code, u will have to write document.txt (the extension) but thats a secondary thing.
}

Edit:
The following code is a code that opens files and outputs the content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
using namespace std;

int main () {
    char c, str[256];
  ifstream is;
  cout << "Name of the file: ";
  cin.get (str,256);
  is.open (str);
  while (is.good())
  {
    c = is.get();
    if (is.good())
      cout << c;
  }
  is.close();
}
i hope this helps
Last edited on
Topic archived. No new replies allowed.