How To Work With C++ Template Libraries Using VC++ MFC Template Libraries

Rate this article
0 out of 5
In this tutorial we will show you how to work with c++ template libraries using vc++ mfc template libraries. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.


Program 
// TemplateExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
/*
This program illustrates the use of MFC Template calss(CArray<data type,data type>) and string 
Handling(CString) classes, writing your own class (CStudent),
Manipulating an array of objects(CArray<>) using template classes

  Included these fies in stdafx.h

#include <stdio.h>
#include <iostream.h>
#include <afx.h>
#include <afxtempl.h>

  Note:

  if you are getting some sort of link error in any of your program

  linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/TemplateExample.exe : fatal error LNK1120: 2 unresolved externals

  Please open Project->settings menu,

  after that use this open

  "MFC as a static link library" in the combo box provided.

  Tom


*/

/*----------------------------------- Class Header ------------------------------------------*
Name : CStudent
Date of Creation : 9/17/2004 2:42:46 PM
Type : BASE
Functionality : This class is uses to store all 
information about the student.
---------------------------------------------------------------------------------------------*/
class CStudent
{
public:
CString m_strName;
int m_iAge;

CStudent()//Constructor initialize all variables here
{
m_strName="";
m_iAge=-1;
}
~CStudent()//Destructor
{

}
};




int main(int argc, char* argv[])
{
//CArray is template
CArray<CStudent,CStudent> m_StudentArray;//CArray is a doubly linked list internaly but it will act as dynamic array

int iNoOfStudents=0;
char YesOrNo;
cout<<"*************Student Database*************** ";
cout<<"Please Enter Number of of students";
cin>>iNoOfStudents;
for(int i=0;i<iNoOfStudents;i++)
{
char strName[25];
CStudent Student; 
cout<<" Please Enter the student Name:-";
cin>>strName;
Student.m_strName=strName;
cout<<" Please Enter the student Age:-";
cin>>Student.m_iAge;
//Add this information in the array for future use.
m_StudentArray.Add(Student);

}
cout<<" Do you want to display all informations From The array m_StudentArray(y/n):-";
cin>>YesOrNo;

if(YesOrNo=='Y'||YesOrNo=='y')
{
for(int i=0;i<m_StudentArray.GetSize();i++)
{
CString strData;
strData.Format("%d)Name:-%s, Age:-%d ",i+1,
m_StudentArray[i].m_strName,m_StudentArray[i].m_iAge);
cout<<strData;
}
}

return 0;
}



Source Code

Joined Date :14-Nov-2012
Articles
Posted
60
Messages
Posted
3

KTS InfoTech Training division offers various short-term programming courses for Students and Professionals who are looking for a bright career in the field of Software development.

The programming video tutorials presented in this web site are taken from some of the training sessions conducted by KTS InfoTech.

You can also learn the Programming packages through Internet directly form our English Speaking Technical experts at an affordable rate.

For more details click here and submit your training requirements.




   
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments
   Design  HTML

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud