I got it
Thanks everyone
I got it
Thanks everyone
Hi , I had a question (forgive me I'm new). I was able to get my code working properly thanks to all of your help but had a question regarding your code (RobC). How is it that you did not have to write the pop, front, empty functions in your code. As a beginner I've always had to write the entire stack in a header file and include this file in the main. In your code you didn't have to and I was wondering how was that accomplished. My guess is that the functions I've been taught (pop, top, push) are all included in a library but which one and why wouldn't they teach us that in class
Thanks
>In your code you didn't have to and I was wondering how was that accomplished.
The standard C++ library contains a bunch of useful functions and classes. Among them are templates for a queue and a stack. I didn't have to write them because they were already written and waiting for me to use.
>but which one
Notice that I included <queue> and <stack>. Those are the headers that hold the declarations.
>and why wouldn't they teach us that in class
Most classes will try to teach you the hard way first, then leave you to the wolves so that you can learn the easy way, the hard way. If you haven't guessed, I don't subscribe to that method. I think you should learn how to use the language productively first, then you can delve into details as necessary.
I've seen this a lot, but shouldn't it beOriginally Posted by Robc
Code:if (!in) { cerr << "Unable to open input file" << endl; if (out) out.close(); return EXIT_FAILURE; } if (!out) { cerr << "Unable to open output file" << endl; in.close(); return EXIT_FAILURE; }
>but shouldn't it be
There's no need. Since the destructor will take care of closing the file, you would only be adding redundant clutter to the code. If you were using FILE pointers, however, things would be different and a little more care would be in order:
Code:FILE *in, *out; in = fopen("input.txt", "r"); if (!in) { cerr<<"Error opening input file"<<endl; return EXIT_FAILURE; } out = fopen("input.txt", "w"); if (!out) { cerr<<"Error opening output file"<<endl; fclose(in); return EXIT_FAILURE; }
Right, thanks.