0

I'm going through the book "Object-Oriented Programming in C++" by Robert Lafore. In the chapter called "Streams and Files", sometimes files are opened using for instance ifstream is("edata.dat", ios::binary); and sometimes the syntax file.open("a:test.dat"); (after the object file has been created). The syntax ifstream is("edata.dat", ios::binary); is well explained and I understand it, but he doesn't explain what a: means or why one case is preferable over the other one. I tried to google it, but I'm not sure what to search for. Any help would be appreciated.

Hunter
  • 357
  • 8
  • 15
  • 2
    `a:` specifies a floppy disk drive on microsoft and some other operating systems. I strongly suspect this is not a good book. –  Jul 25 '17 at 23:28
  • @NeilButterworth that's dissapointing to read since I've read about 600 pages and I liked it so far. But thanks for the reply, I guess the easiest thing is to ignore this for now? – Hunter Jul 25 '17 at 23:30
  • 1
    The use of the filename is operating system dependent. The first form uses a file name relative to the current working directory on the platforms I'm familiar with. So does the second form on some of the platforms I use (those based on POSIX). I *think* on Windows the `a:` part indicates a "drive" (originally it was the letter indicating the floppy disk which would be present in all PCs) and it looks like a name associated somehow with a particular drive. – Dietmar Kühl Jul 25 '17 at 23:30
  • 1
    @Hunter It's a great book! I went through it about 12-13 years ago and it really helped me get into the language. Unfortunately, a lot of things change in 16 years (the time since the latest edition was published). Still, replace `a:` with `c:` and you should be good to go. –  Jul 25 '17 at 23:39
  • 1
    I think it's just a misprint. – Benjamin Lindley Jul 25 '17 at 23:40
  • 1
    I've just checked that book. That `"a:test.dat"` is a bug, I think, because afterwards he refers to this file as "GROUP.DAT". But anyway, there's nothing wrong with that. On DOS/Windows based machines, It's just a file on the a: drive. On unixes, it's just a filename, which contain "a:", there's nothing wrong with that. However, I'd recommend to find a newer book. It is pretty old, there are new standards now, so you will have to re-learn a lot of things... – geza Jul 25 '17 at 23:40
  • 1
    @NeilButterworth It's main failing is it is about 20 years old. Hunter, C++ has changed quite a bit in both language and ideologies surrounding it's best practices since the book was published. Strongly recommend reading some more up-to-date materials when you are done with it. List here: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list . You should be able to drop right into the Intermediates. – user4581301 Jul 25 '17 at 23:41
  • Thanks all for the help and tips! I will certainly look at the link @user4581301 refers to. – Hunter Jul 25 '17 at 23:44

1 Answers1

2

a:test.dat is a valid path on DOS and Windows systems. It means "the file named 'test.dat' on the current directory of drive 'a'".

Drives "a" and "b" on DOS and Windows are reserved for floppy disk drives. Modern computers usually don't come with floppy drives anymore, and those drives are thus not accessible. They're still reserved though even by modern Windows, which is why the first storage filesystem starts with "c".

If you replace a:test.dat with c:test.dat, this will refer to the "test.dat" file on the current directory of the "c" drive.

The current directory on Windows can be changed using the _chdir() function. By default, it's the root directory of the drive.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96