Name: Anonymous 2009-03-29 4:09
I'm trying to read from a text file and write into a label one character at a time. I'm new to programming so please don't eat me alive. Instead of displaying the characters, it displays the numeric value of each character. Am I going about this in a completely idiotic way? Will you please tell me how I can either fix my code, or the correct way in which I should be doing this. Thanks.
Here is my code:
void readFromFile()
{
string s;
fstream inFile("C:\\test.txt", ios::in);
while (inFile >> s)
{
for(int i = 0; i < s.size(); i++)
{
switch(s[i])
{
case '!':
case '.':
case '?':
this->lblTheReader->Text += s[i] + L" ";
break;
default:
this->lblTheReader->Text += s[i];
}
}
this->lblTheReader->Text += L" ";
}
inFile.close();
}
Here is my code:
void readFromFile()
{
string s;
fstream inFile("C:\\test.txt", ios::in);
while (inFile >> s)
{
for(int i = 0; i < s.size(); i++)
{
switch(s[i])
{
case '!':
case '.':
case '?':
this->lblTheReader->Text += s[i] + L" ";
break;
default:
this->lblTheReader->Text += s[i];
}
}
this->lblTheReader->Text += L" ";
}
inFile.close();
}