Results 1 to 12 of 12

Thread: .txt

  1. #1

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Talking .txt

    How to read out an textfile and put the items in a textfield in c++?

    Thx,

    Myvar

  2. #2
    I don't know about the second part, but to write to a text file...

    Code:
    #include <fstream.h>
    
    int main()
    {
        ofstream out("myfile.txt");
        out << "test" << endl;
        out << "another line";
        // close the file here, but I forgot how
        return 0;
    }
    Note that this (I think) only works in C++, not C.

  3. #3
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    use "out.Close" to close the file.
    Baaaaaaaaah

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Call me crazy, but wasn't the question about inputting from a file?

    How to read out an textfile and put the items in a textfield in c++?

    I'm thinking he meant "out of" a text file.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    "read out" is an oxymoron, so I just latched on the "out" part.

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Read some tutorials on http://www.planetsourcecode.com on working with the files
    Baaaaaaaaah

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    or if you are working with a windows app, look here

    http://www.vbforums.com/showthread.p...ht=entire+file

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    .txt

    I do not wanna create a file or write something into it. Just want to open the EXISTING Textfile located in the Project Directory, read it Line by Line and show the contents of them 4 Example in a Listbox or in a Textbox or what ever, and then close them cleanly, so as I would do in RPGIV or VB.

    Thx,

    Myvar

  9. #9
    ChimpFace9000
    Guest
    you dont have to actually call .close() because the destructer will do it automatikly.

  10. #10
    I think I remember reading somewhere that you should always explicitly close file streams instead of relying on them just going out of scope...

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by filburt1
    I think I remember reading somewhere that you should always explicitly close file streams instead of relying on them just going out of scope...
    It simplifies everything when you read the code again - you know exactly WHERE the code thinks the file is closed, rather than having to look for the end of the stream's current scope.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    ahhh.. that reminds me of my computer and his wretched KIS principle. (Keep it Simple) it is good though. i have gone back to code i wrote a year ago, with tons of shortcuts, and not comments, and i have no idea what it does!!

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width