Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello everyone Smile | :)
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
 
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 26-Mar-13 21:46pm
Edited 26-Mar-13 21:50pm
v2
Comments
nv3 at 27-Mar-13 3:00am
   
Have you considered using the debugger :-)
mithun_linux at 27-Mar-13 3:14am
   
Nope i havent considered that way ... but my req is to be with MFC wind app
nv3 at 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 at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100