|
-
Oct 13th, 2001, 01:35 PM
#1
Thread Starter
Member
.txt
How to read out an textfile and put the items in a textfield in c++?
Thx,
Myvar
-
Oct 13th, 2001, 01:50 PM
#2
Member
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.
-
Oct 13th, 2001, 01:57 PM
#3
PowerPoster
use "out.Close" to close the file.
-
Oct 13th, 2001, 02:01 PM
#4
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
-
Oct 13th, 2001, 02:02 PM
#5
Member
"read out" is an oxymoron, so I just latched on the "out" part.
-
Oct 13th, 2001, 02:24 PM
#6
PowerPoster
Read some tutorials on http://www.planetsourcecode.com on working with the files
-
Oct 13th, 2001, 02:26 PM
#7
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 13th, 2001, 03:10 PM
#8
Thread Starter
Member
.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
-
Oct 13th, 2001, 04:58 PM
#9
you dont have to actually call .close() because the destructer will do it automatikly.
-
Oct 13th, 2001, 05:26 PM
#10
Member
I think I remember reading somewhere that you should always explicitly close file streams instead of relying on them just going out of scope...
-
Oct 13th, 2001, 05:47 PM
#11
Monday Morning Lunatic
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
-
Oct 13th, 2001, 07:07 PM
#12
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|