Solved

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

Posted on 2006-11-30
14
2,429 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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you include the source code for the entire file?
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Try the following:

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

Expert Comment

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

Author Comment

by:Cyber-Drugs
Comment Utility
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
Comment Utility
Could you try using wifstream instead?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Cyber,

Refer to my last post above yours for an example.

Thanks
0
 
LVL 4

Author Comment

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

Expert Comment

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

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
Comment Utility
oops
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 76
sum13 challenge 24 77
mapBully challenge 6 88
mapAB Challlenge 35 84
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

12 Experts available now in Live!

Get 1:1 Help Now