#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    60
    Rep Power
    12

    Talking Easy Question C++ 5.0


    He is an easy one for yall, but because I am a newbee I don't know how to do it.
    I know you can remove a file by simply saying remove("file.ext")
    the question is how do you create a file
    I tried create("file.ext") that did not work

    just wondering. Thanks for the help
    ~Ronald
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,112
    Rep Power
    1803
    Open it for write access, and close it.

    Clifford
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    60
    Rep Power
    12

    Re:


    Here is my code. It does not create the file out.txt

    fstream bye("out.txt");
    bye.open("out.txt");

    Thanks for the help
    Sincerely,
    Ronald



    No replies found.
  6. #4
  7. No Profile Picture
    Dinesh_P_V
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    India
    Posts
    259
    Rep Power
    0

    Try


    #include<fstream.h>
    int main()
    {
    fstream f("hai.txt",ios::out);
    f.close();
    }

    Here fstream f(.. itself will create the file. f(.. is the constructor. This will create the file
    The other way for this is to use f.open(...

    HTH
    -Murugesan
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    60
    Rep Power
    12

    Thanks for th ereply


    when I input your code I get this error

    error C2226: syntax error : unexpected type 'ios'

    I put the exact code in (with out the face)

    fstream f("hai.txt",ios: out);

    Is that what you had?

    By the way I am running on C++ 5.0
  10. #6
  11. No Profile Picture
    Dinesh_P_V
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    India
    Posts
    259
    Rep Power
    0
    Forums and ofcourse my error. I have not disabled the smilies ;)
    I wrote

    fstream f("hai.txt",ios:: out);

    -Murugesan
    Dinesh_P_V
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    60
    Rep Power
    12
    Ahhh, it works. You are the man,...or woman.
    Anyways thanks so much for the help. I can now continue. Thanks again
    ~Ronald

IMN logo majestic logo threadwatch logo seochat tools logo