-
File streams
I'm trying to write a function that will accept any given handle for a stream, e.g
Code:
void OpenFile(ifstream [name], char FileName[256]);
#include <iostream.h>
int main()
{
const char FILE_STREAM[]="InFile", FILE_NAME[]="Test.txt";
OpenFile(FILE_STREAM,FILE_NAME);
getchar();
return 0;
}
void OpenFile(ifstream [name], char FileName[256])
{
ifstream name;
name.open(FileName);
if(!name)
cout << "Could not open the file.";
}
Any ideas?
-
Include fstream.
Why do you need the stream name (not file but the ifstream name) to be decided by the user? It will have no effect on the program.
-
i just want to write a genric function that can have multiple handles passed. I don't want to be declaring streams in other functions.
-
How would you encrypt a file like this*I got something like this, I want to encrypt it so that no one can *ahem*cheat*ahem* on my RPG*???
-
would some one be able to help me on this, i would be v.greatful
-
Check out the greatest File streams tutorial at:
http://www.cpp-home.com/FileIO_tutorial.php
It explains everything!
-
>i just want to write a genric function that can have multiple handles passed.
You want a function that can take any number of fstream objects?
>It explains everything!
Except how to avoid undefined behavior.
-Prelude
-
For the undefined behavior, just use the try and catch blocks.
-
>For the undefined behavior, just use the try and catch blocks.
Actually, I was referring to the use of void main. And for the record, undefined behavior is no less undefined by wrapping it in exception tests.
-Prelude