2011. 3. 9. 22:08
c++ 코딩시
visual studio 2008버전에서
atal error C1083: 포함 파일을 열 수 없습니다. 'fstream.h': No such file or directory
라는 오류가 발생하게 되면

visual studio 2008 sp1을 깔면 해결된다.

http://www.microsoft.com/downloads/ko-kr/confirmation.aspx?displaylang=ko&FamilyID=fbee1648-7106-44a7-9649-6d9f6d58056e



NONO!! 이게 해결책이 아니다!!!!!!!!
헤더가 잘못된것...!!!
C++에서는 .h붙는 헤더들을 거의 사용 안한다.
fstream.h 가 아닌 ->> fstream 으로 바꿔줘야 함.
이와 더불어, fstream헤더에 포함된 함수정의로,, 사용해야..
예를 들자면
기존의 6.0버전이 이런 식으로 사용했다면..
void read ( ifstream input_file )
{
 listData c;

 while ( input_file.get(c) ) {
  if (c != ' ' && c != '\n' )
   insert(c);
 }
}


이렇게 바꿔줘야. (포인터 식으로!)
void read ( ifstream *input_file )
{
 listData c;

 while ( input_file->get(c) ) {
  if (c != ' ' && c != '\n' )
   insert(c);
 }
}


<답 찾았던 원문참조.>
Sep 26th, 2004

0

fstream.h, I thought it was a standard header....

Expand Post »
I'm trying to write a simple file output program for my class. The error I recieve when I try to compile in VS .net 2003 is the following.

fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory

The code to my program is extremely straight forward as I always test a concept before incorporating it into the final solution. It's as follows:

C++ Syntax (Toggle Plain Text)
  1. #include <math.h>
  2. #include <fstream.h>
  3. #include <iomanip.h>
  4.  
  5. void main()
  6. {
  7. int a[25];
  8. double s[25];
  9.  
  10. for(int n=0; n < 25; n++)
  11. s[n] = sin(3.14159265*(a[n]=n*15)/180);
  12.  
  13. ofstream out("SineDataV2.txt", ios::out);
  14.  
  15. for(n=0;n<25;n++)
  16. out << setw(5) << a[n] <<''<<setw(12)<<s[n]<<'\n';
  17.  
  18. out.close();
  19. }

Any ideas why I can't include it? I'm pretty sure I'm including the correct file as MSDN reference tells me so: http://msdn.microsoft.com/library/de...m_ofstream.asp

Thanks in advance to those that help!
Reputation Points: 11
Solved Threads: 0
Newbie Poster
C#Coder is offline Offline
19 posts
since Sep 2004
Sep 26th, 2004
0

Re: fstream.h, I thought it was a standard header....

>Any ideas why I can't include it?
Yes, fstream.h is not a standard C++ header. Nor is iomanip.h. Come to think of it, void main isn't standard either (regardless of what your compiler's documentation says). If you want to go fully standard, use C headers with the .h dropped and prefix them with C, and use C++ headers with the .h dropped. Then prefix every standard name with std:: (or you can use using namespace std if you want) because all standard names are in the std namespace. Also, there's no need to manually close the file. ofstream's destructor will handle that for you. Lastly, you had a bug where the first loop declares a variable yet you try to use it after the loop. This is wrong because the variable is declared within the scope of the loop and when the loop ends the variable is destroyed. You can do what you were doing with older versions of Visual C++, but not anymore:
C++ Syntax (Toggle Plain Text)
  1. #include <cmath>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. int main()
  6. {
  7. int a[25];
  8. double s[25];
  9.  
  10. for(int n=0; n < 25; n++)
  11. s[n] = std::sin(3.14159265*(a[n]=n*15)/180);
  12.  
  13. std::ofstream out("SineDataV2.txt", std::ios::out);
  14.  
  15. for(int n=0;n<25;n++)
  16. out << std::setw(5) << a[n] <<' '<<std::setw(12)<<s[n]<<'\n';
  17. }
Team Colleague
Reputation Points: 4652
Solved Threads: 1046
Code Goddess
Narue is offline Offline
9,544 posts
since Sep 2004
Sep 26th, 2004
0

Re: fstream.h, I thought it was a standard header....

Greetings,

» Any ideas why I can't include it?
It sometimes depends. fstream is part of the C++ standard, fstream.h isn't.

The difference between fstream and fstream.h
fstream is somewhat more restrictive than the older fstream.h. One would possibly avoid problems by careful use of namespaces, but it would be a lot smarter to stick with one or the other.

You should avoid using the *.h version as much as possible, because some implementations have bugs in their *.h version. Moreover, some of them support non-standard code that is not portable, and fail to support some of the standard code of the STL.

Furthermore, the *.h version puts everything in the global namespace. The extension-less version is more stable and it's more portable. It also places everything in the std namespace.

Conclusion
fstream.h is an old style method of including std C++ headers, and in opposite to fstream you don't have to declare that you're using the std namespace.

It is sometimes recommended to use:
#include <fstream>
using namespace std;

Hope this helps,
- Stack Overflow
Reputation Points: 26
Solved Threads: 4
C Programmer
Stack Overflow is offline Offline
185 posts
since Sep 2004
Sep 26th, 2004
0

Re: fstream.h, I thought it was a standard header....

Thanks Narue and Stack Overflow for your quick and accurate replies!!

All is now good and I can get on with the rest of the lab
Reputation Points: 11
Solved Threads: 0
Newbie Poster
C#Coder is offline Offline
19 posts
since Sep 2004
Jun 1st, 2010
-1

Re: fstream.h, I thought it was a standard header....




출처: http://www.daniweb.com/software-development/cpp/threads/11430

Posted by Triany