CArchive load gives null lines
Hello all,
I am trying to reuse some code from my Visual C++ 2005. I am using CArchive to ReadString the first line of a file into another string. However, I am seeing squares where there should be spaces when I view it in the debugger. Can anyone explain what’s going on here?
Here's the code:
Code:
if( cfSAP.GetStatus(csRegExtractFileRemote, cfsStatus))
{
if( !cfSAP.Open( csRegExtractFileRemote, CFile::modeRead, &ef ) )
{
cout<<"FAILED\n"<<endl;
ef.ReportError();
return FALSE;
}
cout<<"SUCCESS\n"<<endl;
CArchive caSAP( &cfSAP, CArchive::load );
CString csNewLine;
int iTotalLines = 0;
while(1)
{
iTotalLines++;
//
// Read next line from file.
//
BOOL bVal1 = FALSE;
bVal1 = caSAP.ReadString(csNewLine);
if ( bVal1 == FALSE ) break;
printf("CurrentLine : %S ",csNewLine);
I am able to see some junk characters like this
㌳㐵‵†††䡓䙁⁔††䅍乔䵕䕂ㅒ㈰㐳㘵㔴㔶ㅃ㌵䌭㌭㤴㜵‸†††剂䍁䕋⁔†䅍乔䵕䕂㉒"
in csRegExtractFileRemote and also in the bool variable bval1
I am not able to read the lines due ti this bug ,
can any one help me in this
NOTE:This is normal text file contains two lines of information like this
0234568374C186-M-233545 SHAFT MATNUMBER1
0234564565C153-C-349578 BRACKET MATNUMBER2
Re: CArchive load gives null lines
Quote:
Originally Posted by
nini18110
Hello all,
I am trying to reuse some code from my Visual C++ 2005. I am using CArchive to ReadString the first line of a file into another string. However, I am seeing squares where there should be spaces when I view it in the debugger. Can anyone explain what’s going on here?
Here's the code:
Code:
if( cfSAP.GetStatus(csRegExtractFileRemote, cfsStatus))
{
if( !cfSAP.Open( csRegExtractFileRemote, CFile::modeRead, &ef ) )
{
cout<<"FAILED\n"<<endl;
ef.ReportError();
return FALSE;
}
cout<<"SUCCESS\n"<<endl;
CArchive caSAP( &cfSAP, CArchive::load );
CString csNewLine;
int iTotalLines = 0;
while(1)
{
iTotalLines++;
//
// Read next line from file.
//
BOOL bVal1 = FALSE;
bVal1 = caSAP.ReadString(csNewLine);
if ( bVal1 == FALSE ) break;
printf("CurrentLine : %S ",csNewLine);
I am able to see some junk characters like this
㌳㐵‵†††䡓䙁⁔††䅍乔䵕䕂ㅒ㈰㐳㘵㔴㔶ㅃ㌵䌭㌭㤴㜵‸†††剂䍁䕋⁔†䅍乔䵕䕂㉒"
in csRegExtractFileRemote and also in the bool variable bval1
I am not able to read the lines due ti this bug ,
can any one help me in this
NOTE:This is normal text file contains two lines of information like this
0234568374C186-M-233545 SHAFT MATNUMBER1
0234564565C153-C-349578 BRACKET MATNUMBER2
Why are you trying to use a CArchive as if it were a file? That's not what they do or how they work. If you just want to read a text file, use CStdioFile.
Also, it's not necessary to check for existence for a file. If it's not there, your Open will fail and the File Exception will report that.
Re: CArchive load gives null lines
Thanks for thre Reply ,
Since file existance would change for every hour i have to check for the file existance every time whenever i am running the application,
It is an existing requirement to make use of CArchive ,can tell me is there any way to find out the error why it is giving me NULL lines even though there a data in my text file
Re: CArchive load gives null lines
Quote:
I am able to see some junk characters like this
㌳㐵‵†††䡓䙁⁔††䅍乔䵕䕂ㅒ㈰㐳㘵㔴㔶ㅃ㌵䌭㌭㤴㜵‸†††剂䍁䕋⁔†䅍乔䵕䕂㉒"
in csRegExtractFileRemote and also in the bool variable bval1
If you are seeing junk characters in BOOL variable bval1 then something is very wrong indeed as a type BOOL variable holds a number (usually 0 or 1 but can be any integer). How are you 'seeing' junk characters in bval1?
Re: CArchive load gives null lines
Quote:
Originally Posted by
nini18110
Thanks for thre Reply ,
Since file existance would change for every hour i have to check for the file existance every time whenever i am running the application,
It is an existing requirement to make use of CArchive ,can tell me is there any way to find out the error why it is giving me NULL lines even though there a data in my text file
Again, that's not what CArchive does, so if it's a requirement, it's either a stupid one, or you're not understanding it. CArchive serializes objects in a binary format so that object states and relationships can be stored to disk and restored. It's not for reading text files. Whatever you read into a CArchive should have been saved out using one also.
"CArchive Allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted. "
http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx