Question

I am a newbie to C++. I am trying to write a BSTR to a CSV file, but the data when I print with wcout is not matching with data what's present in file.

BSTR tempString;
ofstream outputFile;
outputFile.open("C:\\data.csv",ios::out);
tempString = getData();
outputFile.write(tempString);
outputFile.close();

BSTR getData()
{
   BSTR KBIDValue;
   IStringCollection *KBID;
   KBID->get_Item(0,&KBIDValue);
   return KBIDValue;
}
  1. If tempString = L"TestData" -> I am able to see the same value in file.
  2. If tempString = getData(); where the function returns a BSTR, I am not able to see same value in file.

Could some please clarify this? Also please explain what exactly is the method to write BSTR to file?

EDIT: Added code

Was it helpful?

Solution 2

I have added the following lines of code in my program and giving the results correctly.

ofstream outputFile;
outputFile.open(filePath,ios::out);
outputFile << W2A(CString(tempString));

OTHER TIPS

You are not returning anything!!!

BSTR getData()
{
   BSTR KBIDValue;
   IStringCollection *KBID;
   KBID->get_Item(0,&KBIDValue);
   return KBIDValue;
}

However if you want to convert to some other form and print, look here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top