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

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!
LVL 4
Cyber-DrugsAsked:
Who is Participating?
 
bdunz19Commented:
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
 
AxterCommented:
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
 
Cyber-DrugsAuthor Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
AxterCommented:
Can you include the source code for the entire file?
0
 
AxterCommented:
Try the following:

CString calcFilename;
calcFilename = "run.txt";
ifstream myfile((const char*)calcFilename);
0
 
AxterCommented:
Are you compiling a UNICODE project, or ANSI?
0
 
Cyber-DrugsAuthor Commented:
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
 
bdunz19Commented:
Could you try using wifstream instead?
0
 
jkrCommented:
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
 
Cyber-DrugsAuthor Commented:
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
 
bdunz19Commented:
Hi Cyber,

Refer to my last post above yours for an example.

Thanks
0
 
Cyber-DrugsAuthor Commented:
Brandon wfstream did the trick, cheers! :)
0
 
mahesh1402Commented:
have you tried to
#include<fstream> //#include<fstream> and NOT <fstream.h>

-MAHESH
0
 
mahesh1402Commented:
oops
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.