Acessing file - FIle Handling

Hello friends... I want to access a text file which is not in the BIN folder thro' a TurboC++ compiler
For accessing a text file name qns.txt i can put
fstream f("qns.txt");
but if the text file is NOT in the BIN and is in another folder say, a folder ABC inside BIN, i.e its directory is D:\TC\BIN\ABC\qns.txt then how can i access it through the same method? Is it possible? Then how? Thanks in advance :)
Just put the whole file path.

Remember to escape any backslash characters you use.
i tried it but its not coming quite right...
> escape any backslash
or simply use forward slashes.

@OP: We can't solve a problem when we don't know what the problem is.
closed account (jwkNwA7f)
Use two backslashes.

Hope this helped!
Last edited on
closed account (Dy7SLyTq)
if its not working with the absolute path, try doing a relative path, ie where it is in relation to the program
closed account (jwkNwA7f)
if its not working with the absolute path, try doing a relative path, ie where it is in relation to the program


Oh, sorry, I misunderstood what he meant.
closed account (Dy7SLyTq)
i was talking to op actuall cppprogrammer, however you did just repeat what ihutch105 said
if the file is one level up from the bin folder use:

..\<filename>

if it is one level down in a folder inside bin, use:

.\<foldername>\<filename>

but you must use the escape character "\\" for all backslashes inside quotes so it might look more like:

fstream f("..\\qns.txt");

or

fstream f(".\\folder_inside_bin\\qns.txt");

respectively, hope that helps!
closed account (Dy7SLyTq)
you dont need the dot on windows, unless turbo c++ is a weird compiler.
.. is the "pointer" to its parent folder, which allows you to move up in the file system

. "points" to the current directory. so .\\folder\\other~folder\\whatev.txt
instead of folder\\other~folder\\whatev.txt is like

bool mybool = true;
while(mybool == true)

intstead of while(mybool)

i know its only a dot, but it should still be explained
closed account (jwkNwA7f)
@DTSCode (his post before the one above mine^) Sorry, I didn't see iHutch105's post.
Topic archived. No new replies allowed.