Why can''t one open a file in a different directory , C/C++ Programming

Assignment Help:

Why can't one open a file in a different directory like "..\test.dat"?

A: Since " " is a tab character.

You must employ forward slashes in your filenames, even on operating systems which use backslashes (Windows, DOS, OS/2, etc.). For instance:

#include

#include

int main()

{

#if 1

std::ifstream file("../test.dat"); // RIGHT!

#else

std::ifstream file(".. est.dat"); // WRONG!

#endif

...

}

Keep in mind, the backslash ("\") is utilized in string literals to generate special characters: "\b" is a backspace, "\n" is a newline, and "\a" is an "alert", " " is a tab, "\v" is a vertical-tab, etc. Thus the file name "\version\next\alpha\beta est.dat" is interpreted such as a bunch of extremely funny characters. To be secure, employ "/version/next/alpha/beta/test.dat" in spite of, even on systems which use a "\" as the directory separator. It is because the library routines on these operating systems handle "\" and"/" interchangeably.

 

Certainly you could employ "\\version\\next\\alpha\\beta\ est.dat", however that might hurt you (there's a non-zero chance you'll forget one of the "\"s, a rather subtle bug since most people don't notice it) & it can't help you (there's no advantage for using "\\" over "/"). In addition "/" is more portable since it works on all flavors of Unix, Inferno, Plan 9, all Windows, OS/2, etc., however "\\" works only on subset of that list. Thus "\\" costs you something and gains you nothing: use "/" instead.

 


Related Discussions:- Why can''t one open a file in a different directory

Big M method, I Want a answer for solving the big M method in the topic of ...

I Want a answer for solving the big M method in the topic of simplex method...

String, Write a program that takes 3 small letters as input and sort them a...

Write a program that takes 3 small letters as input and sort them according to their ASCII value.

Developing programs in the c++ programming language., I. COURSE DESCRIPTION...

I. COURSE DESCRIPTION Develops a working knowledge of object-oriented concepts in areas of classes, inheritance, data structures, error handling, templates and file processing.

What are the precautions with function overloading, Precautions with functi...

Precautions with function overloading Function overloading is a boon to designers, since dissimilar names for same functions need not be thought of, which often is a cumbersome

Miss, Depreciation to a salvage value of 0. For tax purposes an item m...

Depreciation to a salvage value of 0. For tax purposes an item may be depreciated over a period of several years, n. With the straight line method of depreciati

String function examples, 1. De ne a function chomp :: String -> String tha...

1. De ne a function chomp :: String -> String that selects a run of repeated characters from the start of a string with the run being as long as possible. For example ch

C programming language, write an algorithm that reads a postive integer n a...

write an algorithm that reads a postive integer n and then finds and prints the sum of all integers between 1 and n (inclusive) that are disvisible by 7. please write this using c

Constant argument, Define  C o ns t a n t a r g u me n t : ...

Define  C o ns t a n t a r g u me n t : T h e a r gu m e n t c a n b e a c on s t a n t a r gu m e n t .    T h e c o

Big-m method, big-m method operation reseach in progrmme c++..

big-m method operation reseach in progrmme c++..

Msp, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd