Solved

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

Posted on 2006-11-30
14
2,444 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 92
Tab names are off by one 5 53
EvenOdd challenge 10 91
Not needed 13 95
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now