loading text file to wstring vector and use textout to display it. strange output

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
Mr. Petzold has left me confused, but it is my own fault. I eventually want to display TrueType fonts being rotated like a windmill for a Fortune 500 company,
in order to impress them. But first, to the essentials. :)

I have a simple text file and in my Win32 program I load each line of the file into a separate line of a wstring array. I also use wifstream to load the file. I do this because I know of no other way to get TextOut to display my strings.

Well, after I have loaded each separate line of the file into its own vector element, I display them on the window I create.
All but two characters print, but a whole lot of weird characters, mainly of some Japanese or Chinese font-- turned sideways at that-- display.
Ill show you snippets of the code. I know you are all very busy, but particularly helpful. Thanks if you have even read only part of this. :)
Following is the code in question:
<pre class="prettyprint" style=" // ***************************************************************
// * Include Files
// ***************************************************************
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

// ****************************************************************
// * Function definition for file-handler
// ****************************************************************
void FileHandler (wstring fileName,
vector<wstring> & fileData,
bool & fileIsGood);

// ****************************************************************
// * Create necessary upkeep variables and call my
// * file-handler
// ****************************************************************
wstring myFileName = L"C:\Users\Lee\Documents\test_text.txt";
bool fileIsGood;
vector<wstring> myFileInfo;
FileHandler(myFileName, myFileInfo, fileIsGood);

if (!fileIsGood)
{
MessageBox(NULL, L"Error Opening File!",
L"Error", MB_ICONERROR);
return FALSE;
}

// ****************************************************
// * File-handling Function Definition
// * (Note: I dont think this is the problem, because
// * I have created an output file after reading the
// * input file data into a vector and storing the
// * results in a text file, which, when viewed, looks
// * quite perfect.)
// ****************************************************
void FileHandler(wstring fileName,
vector<wstring> & fileData, bool & fileIsGood)
{
wstring line;
wifstream myFile(fileName);
wofstream outFile(L"C:\Users\Lee\My Documents\test_output.txt");
if (myFile.is_open())
{
for(int i = 0; myFile.good(); i++)
{
getline(myFile, line);
fileData.push_back(line);
outFile << fileData << "n"; // when I inspect this file, all is well. // Only when I paint it to the screen is there a problem.
}
myFile.close();
}
else
fileIsGood = false;
}

// ****************************************************
// * Now comes the behemoth!!!
// ****************************************************

// ****************************************************
// * Message Switch Within WndProc. Standard Stuff
// * Ill Leave Out.... On to the Paint Function
// ****************************************************
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);

for(int i = 0; i!= myFileInfo.size(); i++)
TextOut(hdc, 0, i*cyChar, myFileInfo.c_str(), myFileInfo[0].size());

EndPaint(hWnd, &ps);
break; [/code]
Here is what the input file looks like:
test_text.txt:
Hello, world.<br/>
Hello, cat.<br/>
"Meow!"<br/>
How cute! :)<br/>
Goodbye, world.<br/>
Goodbye, cat.<br/>
Purr...<br/>
How Cute!<br/>
<br/>
- The End
my other file looks identical.
Yet when I display it to my window I create, I get this:
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/125474







<br/>

View the full article
 
Back
Top