Archived

This topic is now archived and is closed to further replies.

gpalin

std troubles

Recommended Posts

I''m trying to do some file io using ifstreams. When I go to compile, I get two kinds of errors (with the lines fo code they were generated for): error C2653: ''std'' : is not a class or namespace name void GetStringFromFile(std::ifstream& str, char* buf); error C2664: ''ifstream::ifstream(const char *,int,int)'' : cannot convert parameter 2 from ''ios &(__cdecl *)(ios &)'' to ''int'' std::ifstream m_peopleFile(m_peopleFileName, std::ios::binary); In both cases, the code snippets are written exactly as in the book I''m working from. The second one, with std::ios::binary, seems a little suspicious to me. It just doesn''t seem right. Is it? What should I do about this? Should I try using namespace std in the program? Grant Palin

Share this post


Link to post
Share on other sites
I did have the fstream included, but it had the .h on the end. I removed it, and the program compiled this time. Two extra characters, causing about 20 errors...Geez. Thanks a lot!

Grant Palin

Share this post


Link to post
Share on other sites
Yes, the contents of fstream are placed in the std namespace, whilst that of fstream.h are not. You shouldn''t ever use the latter version.

When using the C++ standard library, you should never include the header files with the ".h" suffix.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

Share this post


Link to post
Share on other sites
windows.h and d3d8.h are not standard C++ header files; they relate to specific APIs (windows and DirectX). Only the standard C++ library headers are without the .h extension.

Share this post


Link to post
Share on other sites
for the most part, yeah. And standard C headers (stdio.h, string.h, etc.) are referred to as cstdio, cstring, etc.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites