fstream help

Started by
3 comments, last by nextgengamer 21 years, 10 months ago
Hi all, Can anyone give me a crash course on fstream and how I would read info from a file into my program. I am trying to figure it out with MSDN Visual Studio but its worded to the point where I cant figure it out. thanks NextGenGamer
Advertisement
Check out this page on cplusplus.com:

C++ File I/O

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Thanks for the link

Watch out

This 'tutorial' uses <iostream.h> and <fstream.h>. This is bad. The pre-Standard headers are only there for backward compatibility. The old iostream library has been deprecated (i.e. they would have taken it out completely if it wouldn't break legacy code).

Don't get bad habits. Start with <iostream> and <fstream>. It will save you no small amount of grief when you'll start to actually manipulate the streams.

e.g. The old iostream (file or not) reads into a char[] while the new std::iostream read into a std::string... which means that you don't have to worry about buffer overflow, memory allocation or how to assign and compare strings.

You can find the GNU standard iostream reference there

Edit: Ok, the general principles apply, but not the nitty-gritty details.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on June 27, 2002 1:16:22 AM]

[edited by - Fruny on June 27, 2002 2:16:25 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:Original post by Fruny
This 'tutorial' uses < iostream.h > and < fstream.h >.


Whoops! Sorry, didn't notice that. I guess I should have looked at the page a little more closely.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

[edited by - Chem0sh on June 27, 2002 1:18:18 AM]
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/

This topic is closed to new replies.

Advertisement