Acessing file - FIle Handling

Jul 27, 2013 at 5:05pm
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 :)
Jul 27, 2013 at 5:33pm
Just put the whole file path.

Remember to escape any backslash characters you use.
Jul 27, 2013 at 5:44pm
i tried it but its not coming quite right...
Jul 27, 2013 at 8:08pm
> escape any backslash
or simply use forward slashes.

@OP: We can't solve a problem when we don't know what the problem is.
Jul 27, 2013 at 8:15pm
closed account (jwkNwA7f)
Use two backslashes.

Hope this helped!
Last edited on Jul 27, 2013 at 8:16pm
Jul 27, 2013 at 8:37pm
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
Jul 27, 2013 at 8:41pm
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.
Jul 27, 2013 at 8:43pm
closed account (Dy7SLyTq)
i was talking to op actuall cppprogrammer, however you did just repeat what ihutch105 said
Jul 27, 2013 at 8:45pm
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!
Jul 27, 2013 at 8:49pm
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
Jul 27, 2013 at 9:00pm
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.