Location of Saved File

This is a discussion on Location of Saved File within the C++ Programming forums, part of the General Programming Boards category; For one reason or another i decided not to learn fstream back long ago when learning C++ and now i ...

Location of Saved File

For one reason or another i decided not to learn fstream back long ago when learning C++ and now i decided to do just that. I got a good hold on it but i have one question. how do you denote where the file will be saved, i thought this would put the file in my C drive.

Code:

char filename[] = "c:inutput.txt";

but it did not, it just ended up in the folder my program was in.
Thanks for any help

When specifying a path in windows you need to add a slash between the drive and the filename. You can use forward or backslash ('/' or '\'). The forward slash works on both windows and other platforms, but the backslash is more commonly used with windows.

When programming, the backslash has a special meaning. It is used to create escape characters (like '\n'), So if you use the backslash you must put two into your string:

Well say I send you a program such as my pong or snake game and they use relative paths to locate all the files that the game needs, now if you just move the directory we ever you want it the game still knows were its at because of the relative path. But you can only move the main directory Ex: Snake, but if you move Ex: Snake/screens some where the relative path will fail. But who would move the screens folder out of the game directory. = ]

"./screens/mainmenu.txt"

The "." at the front of the path pretty much will replace the c:/blah/blah/blah stuff all the time.

Try it out and you will see why relative is better. Also "No, relative paths are relative to the current working directory, which may not be the directory of your exe" lets hope that the directory that contains the .exe also has the files needed to run. haha : )

Here if you compile this and you put the .exe and the input.txt file any where on you hard drive (And both .exe and input.txt are in the same folder) the .exe will still know where the input.txt is at because they are still in the same directory because of relative paths. = ]

Here if you compile this and you put the .exe and the input.txt file any where on you hard drive (And both .exe and input.txt are in the same folder) the .exe will still know where the input.txt is at because they are still in the same directory because of relative paths. = ]

You completely missunderstand relative path.
The path is relative to the current working directory and that has little to do with the location of the executable.
Kurt

I'm not going to reply to a fellow idiots post, but please tell me if I was wrong for just tring to show loopshot another way of locating a file? I didn't think this was in order but I appericate helpful advice, thank you to ZuK, CornedBee for pointing that issue out of my code.