|
You can't (that I know of). You'd need to upload one to your own Web site and provide a link for it here.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi
I am trying to print a CString to a file using C++ ofstream. What I do is something like this:
CString cstr = "This is a test";
std::ofstream fTest("TestCString.txt");
fTest << cstr;
fTest.close();
The problem is, the result in TestCString.txt is not the text "This is a test", instead it is something like 002F4BC4, which I couldn't make any sense out of it.
Could someone tell me what the problem is, and since the string in my project MUST use CString, is there a way to print it using ofstream without changing the CString class?
Thanks!
|
|
|
|
|
try
CString cstr = "This is a test";
std::ofstream fTest("TestCString.txt");
fTest << (LPCTSTR)cstr;
fTest.close();
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
fTest << (LPCTSTR)cstr;
TOXCCT >>> GEII power
|
|
|
|
|
When you typecast object of CString with LPCTSTR, internally overloaded operator LPCTSTR will get called. else explicily call function of CString class "operator LPCTSTR()"
This will convert CString object to Long Pointer To Constant String which is acceptable format for ofstream.
The chosen One
|
|
|
|
|
Hmmm, I tried your exact code (without the suggested cast) and it wrote "This is a test" to the file.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You're using VS.NET 2002 or 2003, while the OP is using VC6. Something in either the standard library or in CString has changed enough to fix this issue between the two.
The changes to CString in MFC 7.x are extensive: it's now defined in an ATL header, for a start. It's also a template class: CString is a typedef for CStringT< StrTraitMFC< TCHAR, ChTraitsCRT< TCHAR > > >.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
You're using VS.NET 2002 or 2003, while the OP is using VC6...
Actually, I've never even seen VS.NET 2002 or 2003, let alone used either of them. I am using VS6.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I copied the OP's code into a new Win32 Console project in VC6 (selecting 'An application that supports MFC' from the Wizard). It produced the original output. Opening the project in VS.NET 2003, converting it and rebuilding produced the correct output.
The fault is that the compiler appears to be selecting the class member (of basic_ostream ) operator<<(const void*) for some reason. It's definitely calling CString::operator LPCTSTR to get the pointer whether you include the explicit cast or not.
Have you upgraded to Visual Studio 6.0 Service Pack 6, and could this be a solution to the problem?
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
Have you upgraded to Visual Studio 6.0 Service Pack 6...
Yes, I have SP6.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You have to cast the CString to an LPCTSTR ala
fTest << (LPCTSTR)cstr;
So that the insertion operator uses the right overload.
If you're using unicode, (e.g., L"This is a test" or, _T("This is a test") and unicode is turned on), then you'll want to use a std::wofstream instead of std::ofstream. But you'll still need to cast cstr to LPCTSTR.
If you, like me, tried testing this with cout, try using wcout instead (the cast to LPCTSTR is still required).
|
|
|
|
|
Dear friends,
My brother's company have a PABX within their premises. They have asked me to develop a telephoning system for them.
i) How do I access the PABX,
ii) How do I recognise telephone numbers from the PABX
iii)How do I read from the PABX
iv) How do I write to the PABX
v) How do I connect an inside caller to the ouside reciept
Just using the computer and the PABX with no operator intervention.
I need both logic and syntax answers.
Yours
Lloyd.
|
|
|
|
|
Wisdom2004 wrote:
i) How do I access the PABX,
ii) How do I recognise telephone numbers from the PABX
iii)How do I read from the PABX
iv) How do I write to the PABX
v) How do I connect an inside caller to the ouside reciept
Just using the computer and the PABX with no operator intervention.
First you need to know the make of PABX. Then visit the manufactuers web-site to find out what development tools are available.
Most PABX's today, either connect to a server via USB or TCP/IP.
Some PABX's support TAPI, others have their own custom API. The first thing to do is contact either the supplier or the manufactuer and find out what they support.
Michael
CP Blog [^]
|
|
|
|
|
Hi guys
It's possible to take benefit of serialize on a Single document app. but changing the filename and not having to go to Save_as dialog? I mean,just clicking a button?
Best Regards
Doc
|
|
|
|
|
Sorry guys
It's just calling OnSaveDocument(myfilename) ?
Best Regards
Doc
|
|
|
|
|
Hai guys,
Sorry I must have kind of misformed yu, on my request. Previously I wrote Dailogue Boxes but I meant Dialogue forms.
The point is, I'am able to develop database applications using document forms/views. But I would like to develop them using Dialogue forms/views. When using Document forms, the procedure is clear as there is a provision to specify the Database name,tables e.t.c. But for Dialogue forms, my book says I type some C++ codes(forgive me dont have it here)amongst the header files. But when I compile the program, I have errors and the program can not access the Database/tables.
Please what is the specific code I need to add to my dialogue form application and in which files. Also what changes do I need to make to the Dialogue form properties in order to be able to retrieve a Recordset from a database.
Your friend and partiner
Lloyd
|
|
|
|
|
I using GDI+ to display text but cannot display text with specific character spacing
aaaaaa
bbbbbb
cccccc
dddddd
eeeeee
|
|
|
|
|
After many hours of playing around with the new UI of VS7, I've finally figured out how to add a control member variable to the project.
But is there an automated way to remove said class variables like VS6's classwizard used to be able to do?
I Dream of Absolute Zero
|
|
|
|
|
Visual Studio .NET 2002? I am interested about this, too.
Maxwell Chen
|
|
|
|
|
I'm using VS.NET 2003 (V7.1), but I'm sure the solution (if any) will apply to 2002 also.
So if any VS geniuses outthere knows the answer....
I Dream of Absolute Zero
|
|
|
|
|
Consider an add in?
http://www.codeproject.com/macro/classwizardnet.asp
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Hi
In VC7, there is this compile option /RTCu which helps you detect use of an unintialised variable in debug builds. I tried turning it off in projects properties>C++>Code generation, and rebuilt the solution but the error message still pops up.
Does any one know what I am missing?
Thanks!
|
|
|
|
|
Do you see the /RTCu in your command line?
(I will usually change the *.dsp manually using notepad if the IDE doesn't do it for me. But this is not advisable of course)
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
I have an MFC application which creates a thread to receive a stream of data from another application in bursts.
Now the thread is started by the main MFC program via:-
m_DisplayTextThread = ::AfxBeginThread(CTestGUI1Dlg::DisplayTextThread, (LPVOID) &m_DisplayThreadData);
and passed the pointer (this) of the main MFC application in the structure m_DisplayThreadData in order for it to access the methods/properties of the main MFC application that require updating.
This causes an Assertion fault, and it was suggested (in a previous post) that PostThreadMessage be used to communicate from the thread to the main application.
My question is - what is the scheme to use for this type of activity, where the GUI needs to reflect data received, but when the receive processing is done in a different thread.
How would this be done? I have looked up PostThreadMessage but dont see how to use it.
I have tended to pass into the thread the neccessary data/pointer the thread required, but this time I have problems.
If I use a smple timer in place of the thread all is well, but have to run slow to ensure that I do not loose data.
|
|
|
|
|
I would suggest using PostThreadMessage just to signal to the main thread (MFC application) that something happened in the receive thread.
The receive thread updates the (pointer of the) data passed and just signal to the main thread to do his work.
I personnaly would go for events.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|