my file is failing to open i have a file named numbers.txt with 12 numbers in it
like so :
1
2
3
4
5
.
.
.
through to 12
but it will not open can someone tell me what I'm doing wrong?
p.s the file is stored in my documents whit no other files on my computer matching its name.
I typed it as user input the way Thomas1965 has it hard coded in line 18 as
C:\\Users\\Franco\\Documents\\numbers.txt
and it finally worked my only issue is I have to turn this assignment in online and have no idea as to where my instructor will have the file stored. is there a way around typing the full file path. or do I just specify to the end user to use the full file path?
... my only issue is I have to turn this assignment in online and have no idea as to where my instructor will have the file stored.
Charles Babbage wrote:
On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Translation: It's up to the end user to feed the correct information into the program. Yes, clear instructions can help sometimes but at the end of the day your program only does exactly what the end user tells it to.
It also depends on what IDE you are using. With many IDEs, having the file directly in the same folder as your .exe file will do the trick. This is the standard.
When running a program from VISUAL STUDIO, and not by double-clicking the executable, you'll have to put the text file in your project's directory where all the .cpp and .h files are located. Otherwise, running the program from the IDE will cause Visual Studio to not find the text file.
I ran into this problem with several of my students, already :P
Thank you for your help everyone my instructor never talked about or showed us how to use files in our programs it was more of figure it out yourself deal. Unless he didn't realize that the assignment asked for that. but thank you anyways. You were all very helpful.
It also depends on what IDE you are using. With many IDEs, having the file directly in the same folder as your .exe file will do the trick. This is the standard.
Careful there, that's not a "standard" set in stone anywhere, that's just a common default setting. The relative directory that the executable runs in is actually a user setting.