Thread: Text File I/O

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Text File I/O

    Hi

    I am fairly new to c++ and have been playing around with text file I/O. I can manage to read and write to files which are stored in the top level of the c drive but I can't access the text file if I put it into a sub folder. This is the code I have been using:

    Code:
    ofstream out("c:\\test.txt",ios::out);
    How would I access the file if it was in c:\\Documents\test.txt for example?

    Thanks
    Last edited by Alex1; 12-11-2009 at 04:39 PM.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Code:
    ofstream out("c:\\dirName\\test.txt",ios::out);
    the \ character within a string escapes the next letter. So you need to escape it itself, hence the \\.


    twomers

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    Thanks thats brilliant.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

Tags for this Thread