Author Topic: #include file not found  (Read 7990 times)

Offline PetruD

  • Single posting newcomer
  • *
  • Posts: 2
#include file not found
« on: November 17, 2011, 12:06:51 am »
I've opened a .cpp file with C::B without inserting it in a project and when I tried to compile it, I got "fstream.h : no such file or directory". Am I missing something? Thank you in advance.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: #include file not found
« Reply #1 on: November 17, 2011, 07:29:40 am »
Yes, a modern book to teach you modern c++ :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zabzonk

  • Guest
Re: #include file not found
« Reply #2 on: November 17, 2011, 10:49:20 am »
The header fstream.h is part of C++ from long, long ago before the language was standardised (which happened in 1998). You should not be using it in your code, and you should not be using learning resources that suggest you do use it. The header file you want is fstream, used as:

Code
#include <fstream>

Offline PetruD

  • Single posting newcomer
  • *
  • Posts: 2
Re: #include file not found
« Reply #3 on: November 17, 2011, 04:26:10 pm »
I am bound to use it in my code. I'm participating in an olympiad, and I am only allowed to use this particular header, or maybe stdio in my code.

zabzonk

  • Guest
Re: #include file not found
« Reply #4 on: November 17, 2011, 04:36:31 pm »
Well, it is an "olympiad" run by clueless, know-nothing chumps then. That header is not part of C++.

And this is off-topic. The problem you are having has nothing to do wiith Code::Blocks.

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: #include file not found
« Reply #5 on: November 17, 2011, 04:46:24 pm »
fstream.h and fstream are (should be) the same header. Write fstream.h yourself:

Code
#pragma once
#ifdef  __CPLUSPLUS
#include <fstream>
#else
#error "only for C++"
#endif

Most of compilers do something like this but in opposite fashion  :) They have "traditional" headers (like fstream.h) for backward compatibility and redirect "new style" headers (like fstream) to them. You have only a "new style" header and redirect the "traditional" header to it. Everybody who will compile your program and who will have fstream.h should pass.