Choosing input streams

closed account (Dy7SLyTq)
So I built an interpreter for a language I made, but I can't get the streams right. I have an istream pointer and if they don't supply a cmd line arg, it references the adress of cin, which works fine. however, if they do supply a file in the form of cmd line args, i want to make it reference an ifstream. how do i do that?
1
2
3
4
5
6
7
8
9
10
11
//std::istream *pointer;
pointer = new std::ifstream(filename);
if (!*pointer){
    delete pointer;
    //Return control to caller notifying failure condition.
}
//Since pointer may point to std::cin, we need to know whether it's safe to delete it.
bool free_pointer = 1;
//...
if (free_pointer)
    delete pointer;
Topic archived. No new replies allowed.