Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I/O to text file 1

Status
Not open for further replies.

ds2728

Programmer
Jul 18, 2001
50
0
0
US
i can input and output to a text file as long as the file is in the same directory as the c++ program. but i cant figure out how to input output to a file in a different directory i.e. I:\c++projects any thoughts. thanks
 
If you're writing pathnames in your code, you need to double-up each of your backslashes

Code:
open("c:\\temp\\work.txt");

But you don't need to ask the user to type in two backslashes at a time, they just type in what they see in say explorer.


--
 
or you can go logical from your current directory (in case your folders can be configured by a user.)
In which case iirc, its "..\\" to go up a directory, or "..\\..\\outputFolder\\ouput.txt" to go up 2 levels, then down 1

hth

K
 
or
".\\...." is current directory
"\\...." is root directory
"\\\\...." is network path
in console they are
\...quite the same are for linux
/
./
../

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top