|
You can create another splitters in first splitter right pane and and put your windows here - vertical or horizontal or some other layout you like
|
|
|
|
|
Hi All,
I have to open a binary file and read the line. then compare the line with some string.
My code is:
<br />
ifstream aBinaryfile; <br />
string sinfo; <br />
aBinaryfile.open(fName,ios::in|ios::binary );
getline(aBinaryfile,sinfo);
CString info(sinfo.c_str());
<br />
if(info.CompareNoCase(TEXT("FirstLine"))==0<br />
{<br />
AfxMessageBox("Match"); <br />
}<br />
else <br />
{<br />
AfxMessageBox("not Match");<br />
}<br />
The result suppose to be display "Match" but right now I'm getting "not Match" eventhough content of info is "FirstLine".
Why they both are not equal when both are suppose to be equal?
Is it because I was reading the binary file?
Thank you.
|
|
|
|
|
It doesn't make sense to open a file in binary mode and then use getline, which (sorta) by
definition, is a text-mode method.
I'm pretty sure the string you read has the newline character at the end, which is NOT a match to
your compare string.
if you remove the ios::binary flag it should work
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
The file contains eastern chars in the file.
In order to read the eastern chars I think I do need to open it in binary mode, dont' I?
thanks.
|
|
|
|
|
The file that I have to read is UTF-8 text file. And it contains file name that is in eastern characters like Chinese, Japanese, Jew, etc. as shown in following;
[begin file names]
file1 : c:\temp\פסטיבל סגול ה- 11 - למדיטציה ואהבה.txt
file2 : c:\temp\sampleDocument.doc
file3 : c:\temp\日本側とのアレン.jpg
[/begin file names]
I need to store those info, file name, in the same way they appear in the text file.
then I have to open those files after I got the name of the file with path from the UTF-8 text file. Therefore, I tried to open the file in the binary mode.
Right now,
1) I read the first line, "[begin file names]", then
2) I have to compare if the string that i just read is "[begin file names]" using CString::CompareNoCase(strRead,"[begin file names]")
3) read the next line, which is "file1 : c:\temp\פסטיבל סגול ה- 11 - למדיטציה ואהבה.txt",
if CompareNoCase return zero.
4) store the file name
.
.
.
etc.
right now I am getting "file1: ?????? 11 ????.txt.
How can I read the UTF-8 file so I can get the information from the file correctly ?
I'm using regular C++.
Thanks
thanks.
|
|
|
|
|
pnpfriend wrote: right now I am getting "file1: ?????? 11 ????.txt
You're getting that where? If you look at the string in binary, are all those question marks
the same multibyte character?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Did you consider setting Breakpoints ?
Set a Breakpoint, and SingleStep through the Code. Make (Mental)notes at what you expect to see. vs what's showing. All of us have to do this All the Time,
It's Called 'Debugging'
LateNightsInNewry
|
|
|
|
|
In addition to the other suggestions, why exactly are you mixing MFC (CString ) with STL (string )? There's no reason to use a CString object just for the sake of comparing.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I tried to use MFC CString becasue there is CompareNoCase().
|
|
|
|
|
bool compareNoCase( const char c1, const char c2 )
{
return toupper(c1) == toupper(c2);
}
...
string str,
strComp("FirstLine");
if (str.size() == strComp.size() &&
equal(str.begin(), str.end(), strComp.begin(), compareNoCase))
{
cout << "The strings are equal." << endl;
}
else
cout << "The strings are not equal." << endl;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
For example.
typedef [v1_enum] enum _outlinestyle
{
NoOutline = 0,
SolidLine = 1,
Dash = 2,
Dots = 3,
DashDot = 4,
DashDotDot = 5
} OutLineStyles;
Then I have
[propget, id(33), helpstring("Select one of types:No Outline,Solid,Dash,Dots etc.")] HRESULT OutlineType([out, retval] OutLineStyles* pVal);
[propput, id(33), helpstring("Select one of types:No Outline,Solid,Dash,Dots etc.")] HRESULT OutlineType([in] OutLineStyles newVal);
The PropertyGrid will automatically use
OutlineType one the left side and the following as the selections.
NoOutline
SolidLine
Dash
Dots
DashDot
DashDotDot
What is I want the change "OutlineType" to another language in the PropertyGrid? Same for all the selections. I can't really change the function name to another language. How can I saolve this?
Thanks.
|
|
|
|
|
Call me a late bloomer, but I've been maintaining code for MFC 4.2 and 7.1 for a while and I just noticed in the Visual C++ 2003 documentation does not indicate that CObject::operator new throws MFC exceptions.
What happended to CMemoryException from MFC 4.2?
I'm not sure if this new operator (For CObject) throws or returns a NULL pointer in MFC 7.1. Sorry about the silly question.
|
|
|
|
|
Looking at the source code in VS 2003 .NET, CObject::operator new doesn't throw any MFC
exceptions.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I saw the ::operator new in there but it kinda confuses me as to what it does in the Microsoft compiler. (By default, if there is such a thing)
I've been crawling through MSDN for Visual C++ 2003 for a bit and it's really not clear if ::operator new throws or returns a NULL in Visual C++ 2003.
|
|
|
|
|
bob16972 wrote: and it's really not clear if ::operator new throws or returns a NULL in Visual C++ 2003
Have you seen this article?
The new and delete Operators[^]
I didn't say it would be any more clear after reading this article
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Have I Seen this Article before? No,
Reading the Original Question, I had not seen this article either! Sounds quite Drastic,BUT there is only one additional burden, and that is to register an exception handler as early as possible,(i.e Before any NULL Pointer can occur in User Code. InitApp() seems to be a good place.
At the other hand, very many of us spend most of our coding time to write 'if's' and 'but's to deal with faulting. This clutters up the general flow of the code we write. Exception handeling is in practice seldomly used as a mechanism, mainly because it is complex in nature, and not worth the bother.
This suttle change will hopefully be the impetus for people to learn about the syntax of exception handeling, and ultimately make code and program Syntax clearer.
LateNightsInNewry
|
|
|
|
|
Mark Salsbery wrote: I didn't say it would be any more clear after reading this article
I gave both the local MSDN and the latest online one a go earlier today when the subject came up at work and I was thrown off guard when CObject no longer advertised that it could throw in the 2003 MSDN. I came across this article but it left a few questions still hanging.
Mark Salsbery wrote: I didn't say it would be any more clear after reading this article
ain't it the truth.
Thanks for taking the time out to assist.
|
|
|
|
|
It looks like it's documented under "CMemoryException class" and here:
Exception Handling in MFC[^]
For MFC apps, CMemoryException is thrown, even on non-CObject objects.
For non-MFC apps, std::bad_alloc is thrown.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I came across that stuff as well but I didn't walk away with that fuzzy feeling with how they kinda make us piece it all together when they used to just come right out and tell us that the class throws CXXXXException.
I figured I'd give it a brute force test and you are right, good ole CMemoryException is still thrown so I don't have to scurry about rewriting all my 6.0 code after all.
try {
while (TRUE) {
CxObject* pObject=new CxObject();
}
}
catch (CMemoryException* e) {
TRACE("CMemoryException\n"); // Get's thrown
}
catch (CException* e) {
TRACE("CException\n");
}
catch (...) {
TRACE("Other Exception\n");
}
My machine isn't too happy now (reboot).
Thanks for the assistance!
|
|
|
|
|
bob16972 wrote: I didn't walk away with that fuzzy feeling
No kidding!
I had to test it too, AND I was just looking at it again (Thanks, LateNightsInNewry ).
To start with, the test code in the first article I linked to (that demonstrates the new operator
throw) didn't work - well, not as I expected. That made me question all my assumptions in my
code.
Turns out, if you attempt to allocate a block too big for the platform, it breaks with a debug
message and returns NULL instead of an exception. Not a big deal, I guess - that should be caught
in the debug phase. But still, I was wondering if I had to check for NULL returns too.
Looking at the MFC source, MFC installs its own new handler and has a single static
CMemoryException object that it throws the address of.
I like your test code! Mine was more conservative (why I didn't use an infinite loop, I don't
know LOL)... borrowing from the article:
int * i_arr;
try {
for (int i = 0; i < 1000000; i++)
i_arr = new int[0x0fffffff];
}
catch(...) {
OutputDebugString("caught exception\n");
}
Cheers!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
My whole horror with the Class CException is, that at the Understandable levels, it throws an exception, with a DWORD (QWORD?)number. That's quite simple, a Switch statement will sort what's going on. I can understand that concept. I also understand, that Different people writing different programs, will arrive at the Same exception numbers for different exceptions. I understand that this will be a problem when DLL's Meet.
Somehow, Microsoft devised a scheme which involved development time for derriving a new class from CException, for anything that may go wrong. I understand also that the reason for this is to be able to generate a distinct exception for each case, independent of exception numbering. At the same time, The link between Exception DWORD Numbers for exceptions, and Existing or New derrived exception classes is not very clear in the documentation.
A Point in case is, you use catch(...)in your sample code!as you know, this catches ALL Exceptions. In a Real life situation, how do you only catch those you are interested in and pass the rest on to some other handler.
LateNightsInNewry
|
|
|
|
|
It's actually Microsoft sample code. It worked well for my test because I could put a breakpoint
in the catch block and I could immediately see the exception class without knowing what I'd get.
In real-life, IMO, a catch(...) is pretty useless. How can you possibly know how to proceed
or if it's even safe to proceed after catching an unknown exception?
The CException class is an abstract base class that provides one interface to get an error
message. If there's a DWORD involved, it's in a derived class, and is generally added so one
has a better context to detect why the exception occurred. I'm not sure what the DWORD is you're
referring to The variables added by the MFC exception classes are well documented.
With new CException-derived classes, you're on your own to add what you want.
In real life, AFAIK, exceptions shouldn't be used for simple error handling. Returning an error
code is faster and simpler.
Constructors can't return error codes so throwing an exception is the only way to indicate
failure.
Using MFC, sometimes it's not a choice. The database classes are a good example. Those
exceptions must be handled, and generally it's safe to continue after handling them, and they
also provide detailed error information for logging and/or deciding how to proceed after they
occur.
Hmm, I'm rambling pointlessly
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hi all i m using this line in my outlook addin project but it give error
"unresolved external symbol _IID_IMAPISession", so i search on net for that value,i foud one but when assign that value its as string when i assign that value to a CString object then it gives error cannot covert Cstring to struct _GUUId,
it tried this
#define IID_IMAPISession= "00020300-0000-0000-C000-000000000046"
this but stil same error
struct _GUID IID_IMAPISession= 00020300-0000-0000-C000-000000000046;
tell me what to do.
CComPtr<iunknown> punk;
spMailItem->get_MAPIOBJECT(&punk);
punk->QueryInterface(IID_IMAPISession, (void**)&m_pSession);
tell me what to so that it works i m stuck to that.
Regards.
Tasleem Arif
|
|
|
|
|
You need to include MAPIguid.h I believe.
Then you can use IID_IMAPISession.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
still same problem.
Regards.
Tasleem Arif
|
|
|
|