Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

works for me. Maybe your problem is that you did not include CPacket.h in the document.h. I just put them in the same file, but you can also have them in two different files and include cpacket.h in the other .h.

#if !defined(AFX_TRY5DOC_H__BA63042D_EFBE_45CF_A864_A01C9FB8E010__INCLUDED_)
#define AFX_TRY5DOC_H__BA63042D_EFBE_45CF_A864_A01C9FB8E010__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>

class CPacket //Encapsulates data structs and associated information for easier instantiation.
{
public:
	CPacket();
	virtual ~CPacket();

	bool operator<(const char* str);   //Included for the purpose of vectorization, but not used.
	bool operator==(const char* str);

	struct PeekPacket7
	{
		unsigned short	fProtoSpec;
		unsigned short	fPacketLength;
		unsigned short	fSliceLength;
		unsigned char	fFlags;
		unsigned char	fStatus;
		unsigned long	fTimeStampHi;
		unsigned long	fTimeStampLo;
	}	ppacket;
	
	struct PacketHeader
	{	
		unsigned char	fDestAddr[6];
		unsigned char	fSrcAddr[6];
		unsigned short	fProtocol;
		unsigned char	fPacketData[1500];  /* max packet size */
	}   enetpacket;
	
	int						length;
	unsigned long			packetCount;
	char					timeString[16];
		
};

class CTry5Doc : public CDocument
{
protected: // create from serialization only
	CTry5Doc();
	DECLARE_DYNCREATE(CTry5Doc)

// Attributes
public:
	std::vector<CPacket> theList;

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTry5Doc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CTry5Doc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CTry5Doc)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert …
Drowzee commented: Solved my problem quite effectively with a very clear example. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what makes you think clear() is not releasing all the memory? The way you are using swap() probably desn't work either (my guess) because there is no real vector.

Try this simple example -- there will be no output because after clear() the vector is empty.

int main()
{
	vector<int> theList;
	vector<int> anotherList;
	theList.push_back(1);
	theList.push_back(2);
	theList.clear();
	anotherList.push_back(3);
	anotherList.push_back(4);
	anotherList.swap(theList);

	for(int i = 0; i < anotherList.size(); i++)
		cout << anotherList[i] << endl;
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

here's an easier way to initialize the structures. It's not necessary to initialize each field individually, just flood the entire structure with 0s.

memset(&ppacket,0,sizeof(ppacket));
    memset(&enetpacket,0,sizeof(enetpacket));

In MFC application you can put that vectory array in any of the MFC classes -- most probably either CWin-derived or CDocument-derived class, depending what all needs access to the vector. you may not be able to initialize the vector's size like you posted, but do it in two stages:

class CMyDocument : public CDocument
{
  ...
private:
   vector<CPacket> packlist;
};

// class constructor
CMyDocument::CMyDocument()
{
   packlist.resize(40);


};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you compile and run your program? If not, then you should do so to see the output. But for now, I would change "while(frue)" to something that will limit the output to the first 10 numbers or so and then quit on its own. It will make debugging a little easier.

To get powers of two requires multiplication. for example, 1*2 = 2, 2 * 2 = 4, 4 * 2 = 8, 8 * 2 = 16, ...

Or you can also do it my addition , 1 + 1 = 2, 2 + 2 = 4, 4 + 4 = 8, 8 + 8 = 16, 16 + 16 = 32, ...


with that in mind, now look at your program. the calculations inside the while loop are all wrong. all you need is one variable -- f0 -- and add it to itself

int f0 = 1;

// power of 2
f0 = f0 + f0;
cout << f0 << ", ";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

first make sure your computer meets minimum specs for XP. See Microsoft's Windows XP Upgrade Advisor


also read this if you havn't already.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why are you reformatting the hard drive that often??? Are you getting a lot of viruses? If yes, stop visiting all those pron sites :cheesy: I've had mine installed over 3 years now and never reformat/reinstall the os. Reformatting the hard drive just to improve performance does little, if any good.

The best way to improve performance is to just defragment the hard drive. XP has built-in defragmenter that you can use. Just double-click MyComputer, right-click on the drive you want to degragment, select properties, select Tools Tab, and hit the "Defragment Now" button.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

can anybdy help on this question......write a program that uses a for statement to calculate and print the average of several integers. assume the last value read is the sentinel 9999. a typical input sequence might be.

10.....8......11.....7.....9.......9999

why are you hijacking this thread? create your own new thread. :(

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

functions in <ioman>. Here are other values that can be used for setioflags function.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	float n = 123.456F;
	// output float with 5 decimal places
	cout << setprecision(5)  << setiosflags(ios_base::fixed) << n <<  endl;
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suppose I should make a post here -- afterall I just joined today. I'm not called "Ancient Dragon" for nothing -- no disrespects intended for dragons :rolleyes: Got this handle from when I played the role playing game Dungeons & Dragons about 10-15 years ago. Few, if any of you were thought of yet when I graduated from HS, when gas prices were $0.195 USD/gallen, we just got our first McDonald's a year earlier, Elvis was still making movies, JFK was President of the US, and Queen Elizabeth II had only been Queen about 9 years (yes, I remember watching her coronation live on B&W TV).

I have been married to the same woman (my HS sweetheart) for 43 years, have 2 grown children and 2 grandchildren. My grandson is just starting HS this fall, and my grandaughter graduated HS a year ago. I started a vigorous exercise program two years ago to keep all my body parts moving and still go there 4 times a week for 40 minutes each.

Hope to see yea around often :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How do I make a constructor for those unsigned char arrays? Should I make a loop, or can I just initialize the first element of an array and call it good?

c-style char arrays do not have constructors. you must allocate the memory in the container class. Are the arrays pointers what need to be allocated? or arrays of hard-coded size?

class myclass
{
...
   char* array;
   // or
   char array[1000];
}

directives to isolate the class to one defintion, but for some reason...If I put this class in there, only the class itself is protected by the preprocessor. If I put the class constructor outside the terminating bracket for the class, I get "already defined in suchandsuch.obj" errors.

And it's the same with the overloaded operator functions.

you don't put executable code (except inline code) in header files for the very reason that you state -- duplicate functions. Instead, put the class declaration inside the defines and put the implementation code in a *.cpp file. Same for overloaded operators.

You need to post some code before anyone can give you exact answers to your questions. Here is an example:

// myclass.h
#ifndef _MYCLASS_H
#define _MYCLASS_H
class myclass
{
public:
   myclass();
   virtual ~myclass();
  // overload operator
   bool operator<(const char* str);
   bool operator==(const char* str);
   // global overloaded operator that is not part of the class
   friend bool operator<(myclass& mc,const char*s);

protected:
  char array[1024];
};
#endif // _MYCLASS_H

// myclass.cpp
myclass::myclass()
{
   // initialize array
   memset(array,0,sizeof(array));
}


bool …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

have you tried to find answers with google?

http://www.msfn.org/board/lofiversion/index.php/t52710.html

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are using c++ -- why are you mixing c-style char arrays when you could be using std::string class that will do all the allocation for you. Post your class and we'll see how to get rid of those char arrays!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

depends on you. how easily do you learn new programming languages? My opinion: c++ is more difficult to learn mainly because it will let you stab yourself in the back. If I were you, I would learn both languages -- but not at the same time.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you will probably get better response on the C/C++ board.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

does your computer meet minimum system requirements ? also check out hardware compatability lists

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually, VB6 is rarly used outside educational institutions. If you want to make programming a professional career you will have to learn c++, and learn it pretty thoroughly. Most software houses use c++, but M$ Visual .NET is picking up speed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It uses opendir() and readdir().
Which is just a more verbose and flexible way to get the same effect as calling scandir(). By the way, you can google with "man function" if you aren't on a Linux or Unix system to see how they work. It's easier than saying "I don't know about this, but here's an identical solution that I heard someone talk about once".

I never heard of scandir(), but I'm glad *nix os writers got smart and made it a little easier. :p And glad you mentioned how to google for man pages -- good to know. :idea:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You didn't mention the operating system you are using. If MS-Windows, then you can use _findfirsrst() and _findnext() to transverse through the file system. When a sub-directory is found, just merly make a recursive call to the function.

*nix is somewhat different. It uses opendir() and readdir(). I don't know *nix enough to explain more, but you progably goole for those functions and you should be able to find code.

Here is the basic algorithm for searching MS-Windows file system. If you use it, you will have to modify it to suit your application -- such as collect filenames in a hash table.

//
// include files
#include <stdio.h>
#include <io.h>
#include <string.h>

void FileFinder(const char* path)
{
	struct _finddata_t data;
	char buf[255];
	// Crete the initial filespec string, which may contain * or ?
	// wild cards.  To specify all files, use "*.*".  You can also limit
	// the search to certain file extension, for example to find all the
	// files with .txt extension the filespace is "*.TXT" -- MS-Windows is
	// not case sensetive, so *.TXT is the same as *.txt and *.tXt.
	strcpy(buf,path);
	strcat(buf,"\\*.*");
	long n = _findfirst(buf,&data);
	if(n >= 0)
	{
		do {
			// check if not current or parent directories
			if(strcmp(data.name,".") != 0 && strcmp(data.name,"..") != 0)
			{
				if(data.attrib & _A_SUBDIR)
				{
					// this is a directory.  So make recursive call
					// to search it.
					strcpy(buf,path);
					strcat(buf,"\\");
					strcat(buf,data.name);
					FileFinder(buf);
				}
				else if( data.attrib & (_A_NORMAL | _A_HIDDEN | _A_ARCH))
				{
					// …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you should probably update your tutorial to use current c++ standards -- The information is very very old and many of it obsolete. This makes it pretty difficult for new c++ programmers to weed through the chaff to get to the good stuff.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

also check other spellings -- base class has Stream parameter, but derived class shows Stream*. I suspect base class is incorrect.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

derived class declaration of the pure virtual function must be EXACTLY like that in the base class, minus the "= 0" part. You forgot the word virtual in the derived class. I find it easy to prevent that kind of error by copy-past from base class to derived class.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

since you are using dev-c++ compiler I assume you are programming on some version of MS-Windows operating system. See win32 api function MoveFile() or MoveFileEx(), which will move a file or an entire directory.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A factorial is n * (n-1) * (n-2) * .... so all you need is a simple loop to calculate the factorial

long n = 5;
long total = 1;
while(n > 1)
{
  total = total * n;
  --n;
}
// output result
cout << total << endl;

[edit]Sorry about duplicating a previous answer. I didn't see them when I posted this. :( [/edit]

<M/> commented: your very first post :D +8