std troubles
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
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
Grant Palin
Yes, the contents of
When using the C++ standard library, you should never include the header files with the "
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
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 ]
Well, that''s interesting. The book I''m working from uses includes with the "h"
e.g.
#include <windows.h>
#include <d3d8.h>
etc
Grant Palin
e.g.
#include <windows.h>
#include <d3d8.h>
etc
Grant Palin
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.
Do the standard C++ headers have the same name as the other kind, except without the .h at the end?
Grant Palin
Grant Palin
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.
How appropriate. You fight like a cow.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement