I'm getting a segmentation fault on overloaded '<<' operator, however, if I run my program with a command line option (reading a file specified on the command line), the program works just fine... However, if I enter the file manually it will seg fault.
I've told you already what the exact error message is. I run the program, I enter a file name in, it pops out "Segmentation Fault" and the program exits. Using the debugger isn't useful here in this case as it's not really telling me what's going on other than a seg fault occured and it exited.
On line 33, you create a pointer named filename. You do not initialize it, so it points to random garbage memory. On line 37, you pass that pointer to getFilename, which then attempts to read string data to that address, effectively corrupting the heap and likely causing a program crash.
The easy solution here: don't use pointers until you understand what they are and what they do. If you want to use strings, use std::string:
What you said makes sense Disch, and I thought I had a decent understanding of pointers (although they can be screwy at times). I didn't realize I had done what I did there, but it makes sense. So it wasn't my extraction operator, it was a function using essentially an uninitialized variable (I dynamically allocated it, it should be good to go now). Thanks!
(I dynamically allocated it, it should be good to go now).
I still strongly recommend you use strings instead of dynamically allocating your own char arrays.
There is little reason to use char arrays in C++. Especially with iostream.
EDIT:
In fact, I'm almost certain that you made some other kind of program-breaking mistake with dynamic allocation. I can already see some pitfalls you may have missed with how your existing code is written.