Solved

error C2079: 'myfile' uses undefined class 'basic_ifstream<char,struct std::char_traits<char> >'

Posted on 2006-11-30
14
2,455 Views
Last Modified: 2013-11-20
Hi guys,

My application compiles fine in Debug, but I am now trying to Compile in Release, and am getting this error:

error C2079: 'myfile' uses undefined class 'basic_ifstream<char,struct std::char_traits<char> >'

One this line:

ifstream myfile(calcFilename);


Any ideas on how I can fix this?

Cheers!
0
Comment
Question by:Cyber-Drugs
  • 4
  • 4
  • 3
  • +2
14 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 18045965
Hi Cyber-Drugs,
Please post your code, and not just the one line.

Make sure you have #include <iostream> and not #include<iostream.h>

Also check if you have using namespace std;

David Maisonave (Axter)
Cheers!
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18046047
Hi Axter,

I have the correct include, as well as the namespace std, and here is the code:

CString calcFilename;
calcFilename = "run.txt";
ifstream myfile(calcFilename);
0
 
LVL 30

Expert Comment

by:Axter
ID: 18046084
Can you include the source code for the entire file?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 30

Expert Comment

by:Axter
ID: 18046097
Try the following:

CString calcFilename;
calcFilename = "run.txt";
ifstream myfile((const char*)calcFilename);
0
 
LVL 30

Expert Comment

by:Axter
ID: 18046106
Are you compiling a UNICODE project, or ANSI?
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18046229
Unfortunately, I can't include the source for the whole file as it's over 3000 lines...


ifstream myfile((const char*)calcFilename);

Didn't work....

I believe the project is in UNICODE
0
 
LVL 4

Expert Comment

by:bdunz19
ID: 18046283
Could you try using wifstream instead?
0
 
LVL 86

Expert Comment

by:jkr
ID: 18046304
If the project is UNICODE, the CString class also is, which means that you have to convert to ANSI ('ifstream' does not work with UNICODE filenames), e.g.

#include <atlbase.h>

//...

USES_CONVERSION;
CString calcFilename;
//...
const char* pszFile = W2A((LPCTSTR)calcFilename);
ifstream myfile(pszFile);
0
 
LVL 4

Accepted Solution

by:
bdunz19 earned 500 total points
ID: 18046354
jkr, I'm pretty sure fstream does work with unicode.

the unicode version is: wifstream

example:

#include <fstream>
using namespace std;

...

wifstream myfile(calcFilename);
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18046368
jkr,

Your code gives this error on compile:

error C2440: '=' : cannot convert from 'const char *' to 'const unsigned short *'


Brandon,

Could you give me an example of how to use wifstream, and what includes are required for it please?
0
 
LVL 4

Expert Comment

by:bdunz19
ID: 18046388
Hi Cyber,

Refer to my last post above yours for an example.

Thanks
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18046400
Brandon wfstream did the trick, cheers! :)
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 18046415
have you tried to
#include<fstream> //#include<fstream> and NOT <fstream.h>

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 18046421
oops
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
NotAlone Challenge 20 83
matchUp  challenge 9 110
Sed question 2 86
Message not shown 5 50
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question