Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fstream >> CString error

Status
Not open for further replies.

classic773

Programmer
Jun 14, 2001
57
US
I'm getting a "error C2678: binary '>>' : no operator defined which takes a left-hand operand of type 'class fstream' (or there is no acceptable conversion)"
from:
fstream pref_file;
CString something;
pref_file.open("prefs", ios::in|ios::nocreate);
if(pref_file.is_open())
{
pref_file >> something;
}

Why? I read in MSDN that CString includes >>
 
hmm, on further inspection it says >> is overloaded for CArchive, which means they were to lazy to overload it for streams. So I guess I have to >> LPSTR then convert the LPSTR to a CString
 
shoot nevermind
i had LPSTR = CString, rather than the other way around
Gosh its only 11 and i'm already frustrated
 
I found that the best(only) way to read from a file into a CString is using CStdio
 
Convert LPSTR to to CString is easy
myCString=CString(myLPSTR);

Yes CStdio has the ReadLine and WriteLine useful for text files, for the other files(binary, for example an image) more fit are CFile, CMemFile. s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
I cant understand, why are you using CStrings with fstreams? If you are using MFC already, use CFile. John Fill
1c.bmp


ivfmd@mail.md
 
Ummm, the reason is that I had unix c++ code that I'm making a visual c++ program out of : ) I'm new to visual c++ so I don't know all the new mumbo jumbo
 
I should ask visual c++ questions in a Unix forum? that doesn't seem quite right. I have code that I wrote to run on windows using Cygwin ("unix style") compiler. I copied and pasted it into a visual c++ workspace to be run with a dialog window. This is certainly a Visual C++ question.
 
Instead of making a code to be VisualC++ after copy/paste from a less compatibility library, you try to make it Unix. At the first, if you're using CString, set in project settings Using MFC as a Shared DLL or as a statically linked library. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top