How to read out an textfile and put the items in a textfield in c++?
Thx,
Myvar
Printable View
How to read out an textfile and put the items in a textfield in c++?
Thx,
Myvar
I don't know about the second part, but to write to a text file...
Note that this (I think) only works in C++, not C.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;
}
use "out.Close" to close the file.
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.
:)
"read out" is an oxymoron, so I just latched on the "out" part. :D
Read some tutorials on http://www.planetsourcecode.com on working with the files:)
or if you are working with a windows app, look here
http://www.vbforums.com/showthread.p...ht=entire+file
:)
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
you dont have to actually call .close() because the destructer will do it automatikly.
I think I remember reading somewhere that you should always explicitly close file streams instead of relying on them just going out of scope...:confused:
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.Quote:
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...:confused:
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!!