Hi,

I'm having a problem with using the streamWriter to write to a unicode file.
Code as follows:

for(int i = 1; i < 1018; ++i)
{
	std::wostringstream integer;
	integer << L"IDS_STRING" << i << L"\t";
	wstring thisString = integer.str();
	thisString = thisString + L"\"Spare String\"";
	wchar_t* SpareString = const_cast<wchar_t*>(thisString.c_str());
	bool isPresent = std::find_if(load.begin(), load.end(), StartsWith1(thisString)) != load.end();

	System::IO::StreamWriter^ WriteSpareStrings = gcnew System::IO::StreamWriter(L"Chinese.txt", true, System::Text::Encoding::Unicode);
	if(isPresent == false)
	{
		WriteSpareStrings->Write(SpareString);
		WriteSpareStrings->Write(L"\r\n");
	}
	WriteSpareStrings->Flush();
	WriteSpareStrings->Close();
}

So, obviously I'm expecting the output to the file to be strings of "IDS_STRINGi "Spare String"", but instead all the strings are just written "True".

I have a warning as follows:
'warning C4800: 'wchar_t *' : forcing value to bool 'true' or 'false' (performance warning)'

This obviously gives me an idea that it's coming from the line - WriteSpareStrings->Write(SpareString) and that it doesn't like wchar_t* being used there, but I don't know a way of fixing it.

I've tried writing each separate part alone, which works apart from writing the integer, where it just prints out strange characters (probably to do with using Unicode?).

If anyone has any insight on how I can fix this, I'd greatly appreciate it.

Thank you

Can you convert that wchar_t* to an actual String^ first?
...and since you're adding the \r\n, can you just use WriteLine() on the line before?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.