954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

StreamWriter output coming out as 'true'

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

ahoysailor
Newbie Poster
14 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

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?

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: