Archived

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

std troubles

This topic is 5560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites
you did #include <fstream>, right? Without the .h?

How appropriate. You fight like a cow.

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 on other sites
Interesting choice of title

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 on other sites
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

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 on other sites
Do the standard C++ headers have the same name as the other kind, except without the .h at the end?

Grant Palin

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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• Forum Statistics

• Total Topics
632935
• Total Posts
3009304
• Who's Online (See full list)

There are no registered users currently online

×