reading and writing to files

This is a discussion on reading and writing to files within the C++ Programming forums, part of the General Programming Boards category; im trying to make this game trainer but when i try and write/read files outside the folder where the .exe ...

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    reading and writing to files

    im trying to make this game trainer but when i try and write/read files outside the folder where the .exe it wont compile
    i get all these errors like

    24 C:\Documents and Settings\wmorrish\Desktop\New Folder\main.cpp:7 [Warning] unknown escape sequence '\D'

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main()
    {
        string data;
        ifstream open_file("C:\Documents and Settings\wmorrish\Desktop\New Folder\new", ios::in);
        getline(open_file, data);
    }

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    \ in a string signifies an escape sequence. If you're looking for \, you need to put \\.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > ifstream open_file("C:\Documents and Settings\wmorrish\Desktop\New Folder\new", ios::in);

    Backslash is used to start an escape sequence, so use double backslashes:
    ifstream open_file("C:\\Documents and Settings\\wmorrish\\Desktop\\New Folder\\new", ios::in);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading and writing files
    By jcafaro10 in forum C Programming
    Replies: 8
    Last Post: 04-08-2009, 11:36 PM
  2. writing and reading files
    By oldie in forum C Programming
    Replies: 1
    Last Post: 07-03-2008, 05:54 PM
  3. Reading and Writing from files
    By dutch's finest in forum C Programming
    Replies: 8
    Last Post: 03-18-2004, 04:34 AM
  4. reading and writing to files in windows
    By Dohojar in forum Windows Programming
    Replies: 8
    Last Post: 06-26-2003, 03:07 AM
  5. Reading binary files and writing as text
    By thenrkst in forum C++ Programming
    Replies: 8
    Last Post: 03-13-2003, 10:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21