last day (14 days later) » 

12:54 AM
0
A: Reading an text file into an array of strings

user657267Hardcoding a filename into a program is not usually a good idea, for something this simple you can use std::cin and redirect the input stream when you run your app as long as you don't need std::cin for user input. If you do need to use an ifstream pass the filename using argv and use the command...

 
It's a good idea in a lot of situations; why is it not in this one?
 
@CoffeeandCode One reason is because filenames and paths aren't always portable.
 
Yes, but in this situation it doesn't matter. Putting a simple file name will always search the running dir for a file.
 
@CoffeeandCode which was exactly the cause of OP's issue in this case, the file wasn't there.
 
You seem to imply that typing the file name instead of hard-coding it would have made it, somehow, be there.
I suppose he wouldn't have to keep it in the same directory though, which he seemed to want to do.
 
12:54 AM
@CoffeeandCode If the filename were external OP could have relied on features such as autocomplete to make sure he was passing a valid filename.
 
Hard-coding a file name would usually be to enforce a valid file be present, though
 
Hi, how's it going
 
I accidentally clicked the thing :L lel
 
Lol Well it makes sense anyway rather than spamming up the comments
 
Yeah, I was just saying that it may be to set a user-requirement of having that file present with the executable, das a good use of hard-coded file paths mane
 
1:00 AM
Sure, I suppose the best way of handling it would be to use both a hardcoded name to fall back on and give the user the possibility of overriding it
 
Like, I have a hard-coded filepath in my engine for loading a file if the user doesn't specify
Yeah, exactly as I was saying haha
 
But the thing with hardcoded names is they are prone to problems resulting from encoding and pathnames, if portability is important they should probably be avoided./
 
Yeah, unless in root directory, but if they aren't platforms will treat for example "/file" differently
I wish everything would just follow POSIX, then life would be easy
 

last day (14 days later) »