Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-30
14
Medium Priority
?
2,681 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

824 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