We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,415 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

2
Contributors
1
Reply
12 Minutes
Discussion Span
1 Year Ago
Last Updated
2
Views
ahoysailor
Newbie Poster
14 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0666 seconds using 2.83MB