Click here to Skip to main content
15,881,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone :)
Warm Greetings !!!
I have created a SDI Application to display a text fle after tokenizing it. While creating SDI application i gave the base class as "CView" .
My requierement is in the output window i have to click File->Open->"xxx.txt" and the output needs to be displayed.
The text file contains following data
A-B:C,D

The code that i have written is as follows

C#
void CFileView::OnFileOpen()
{
	// TODO: Add your command handler code here

	CString pathname,strLine; 
	CStdioFile File; 

	if(File.Open(pathname, CFile::modeRead)) // Open file to be read 
	{ 

		while(File.ReadString(strLine)) // Read file 
		{	
			int Position = 0; 
			CString Token; 

			Token = strLine.Tokenize(_T("-:,"), Position); 
			while(Token!="") 
				{ 
					_tprintf_s(_T("Token: %s\n"), Token); 
					Token = strLine.Tokenize(_T("-:,"), Position); 
				} 
		}
	}

}


But in the output screen when i open a file im not getting anything .. Please Help
Posted
Updated 26-Mar-13 20:50pm
v2
Comments
nv3 27-Mar-13 3:00am    
Have you considered using the debugger :-)
mithun_linux 27-Mar-13 3:14am    
Nope i havent considered that way ... but my req is to be with MFC wind app
nv3 27-Mar-13 3:58am    
Put in a breakpoint and single-step through your code and you will see what's going wrong. The ability of using a debugger is an absolute must for every serious programmer.
mithun_linux 27-Mar-13 5:03am    
fine break point ll do i guess.. but can u please comment on the base class of SDI that i have used .. is that okay with the "CView" class or should i change with someother for dealing wit parsing and displaying of text files.??
nv3 27-Mar-13 5:12am    
The view class is normally not the right place to do the processing of your file. Instead I would put the parser into the Document class. But that's one of the finer points of design. First you want to get that little parser do its job. And get familiar with the Visual Studio debugger! It is very intuitive and your best friend if you develop something with more than three lines of code.

1 solution

You are using _tprintf_s which prints a formatted string to stdout, as described here on MSDN[^]. You need to create an internal structure, array or similar in the file reading code, which will contain all your tokens in some useful order. Then in your OnPaint method you render that data onto your SDI client view, tabulated according to your requirements. There are lots of samples in the articles section that should show you how to do it.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900