Click here to Skip to main content
13,005,920 members (100,194 online)
Rate this:
Please Sign up or sign in to vote.
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

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); 
					_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 20:46pm
Updated 26-Mar-13 20:50pm
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

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170628.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2017
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