You are returning an object created within a certain scope. Returning the array will point to memory that you should no longer try to read / write. Create the array on the heap, but then this leads to who is responsible for cleaning up the memory.
Quote:void load( char* filename, string& out ) { ifstream fin(filename) fin >> out; }
etc
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Noir so you must fix that function to:
char *load( char *ptr) { ... }
Returning a pointer to a local variable ... recipe for disaster.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanks for all the help so far! ;). I was trying that last submission and i get... 11 C:\Dev-Cpp\Cpp CodeTest\fileinput.cpp conversion from `const char*' to non-scalar type `std::basic_ifstream<char, std::char_traits<char> >' requested
Quote:Original post by mcgrane66 Thanks for all the help so far! ;). I was trying that last submission and i get... 11 C:\Dev-Cpp\Cpp CodeTest\fileinput.cpp conversion from `const char*' to non-scalar type `std::basic_ifstream<char, std::char_traits<char> >' requested
The constructor is explicit. You need to write ifstream fin(filename.c_str());
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan