I have generated a binary file using binary writer in c# which I have to read it using CArchive class in VC++.
File contains the string of length more than 190 characters. But when I try to read it using CArchive class it reads 1 extra white space at the start of the string hence it skips the last character of the string which is causing problem in reading next integer value.
(Note: I have already applied Trim() before writing the string in file)
static void Main(string[] args)
{
using (FileStream stream = new FileStream("E:\\BinaryFile.dat" , FileMode.Create))
{
using (BinaryWriter writer = new BinaryWriter(stream, Encoding.ASCII))
{
int user = 99;
writer.Write(user);
string versionMain = "Ra-1:8:10[60],9:00[60],10:01[60],11:30[60],9:10[60];";
versionMain += "Fast And Flurious:8:10[60],9:00[60],10:01[60],11:30[60],9:10[60];";
versionMain += "Pirates Of Carebian :Ra-1:8:10[60],9:00[60],10:01[60],11:30[60],9:10[60]";
writer.Write(versionMain.Trim());
int memDetailsKey = 1234;
writer.Write(memDetailsKey);
}
}
}
In other vc++ application I am just reading this file using object of CArchive class. I am able to read first integer value but when I try to read versionMain string it reads as " Ra-1:8:10[60],9:00[60],10:01[60],11:30[60],9:10[60];Fast And Flurious:8:10[60],9:00[60],10:01[60],11:30[60],9:10[60];Pirates Of Carebian :Ra-1:8:10[60],9:00[60],10:01[60],11:30[60],9:10[60". Last ']' is getting skipped which is causing error in reading next integer value.
Please suggest any solution.