pseudorandom21 166 Practically a Posting Shark

Microsoft unicode stuff.

http://msdn.microsoft.com/en-us/library/aa272960%28v=vs.60%29.aspx

You will likely opt to use either the "char" type of string, or the "wchar_t" type.
Visual Studio provides a std::wstring.

http://msdn.microsoft.com/en-us/library/wt3s3k55%28v=vs.71%29.aspx

Note that wstring is a basic_string<> templated to wchar_t.

You may also opt to convert the "char" string to "wchar_t".
See MultiByteToWideChar: http://msdn.microsoft.com/en-us/library/dd319072

pseudorandom21 166 Practically a Posting Shark

I agree with jonsca, the string class is managing that memory and implementations vary.

http://www.cplusplus.com/reference/clibrary/cstring/strtok/

pseudorandom21 166 Practically a Posting Shark

Are you aware this is making an array of pointers? Event *events[MAX]; I think it would be best for you to review the basics of pointers and dynamic memory allocation, you leak memory for the Event you allocated.

Some better style may help you detect errors, by initializing the array of pointers to NULL or nullptr, you will receive the dreaded dereferencing null pointer exception at runtime when trying to use an un-init'd pointer or a deleted one--but you will know what it means.

Simple guidlines:

//Initialize to NULL/nullptr
char *buffer = NULL;

buffer = new char[1024];

//Always delete the memory when finished with it.
delete [] buffer;

//Followed by setting pointer to NULL.
buffer = NULL;
pseudorandom21 166 Practically a Posting Shark

It looks like you need to know how to do this, but I'm kind of unsure, because it's very simple to do...

for(size_t i = DIM1 - 1; i > -1; i--)
{
  for( size_t j = DIM2 - 1; j > -1; j-- )
   ;//...
}
pseudorandom21 166 Practically a Posting Shark

Is there a way to define a property with default get/set functionality for a variable?

pseudorandom21 166 Practically a Posting Shark

What problems are you having?

pseudorandom21 166 Practically a Posting Shark

Unfortunately I don't think it's possible to have two windows in focus at the same time on Windows. I don't think the OS works like that.

pseudorandom21 166 Practically a Posting Shark

I really don't think this belongs here.

pseudorandom21 166 Practically a Posting Shark

user422, it's perfectly fine if you understand the order of operations with regard to * and ++, but I don't remember them exactly so I typically will include parentheses, even when not required, so as to make more clear the intent.

pseudorandom21 166 Practically a Posting Shark

My source is stack overflow, a person citing Knuth as his source. Unfortunately I've lost the page, and there wasn't a better answer as far as I was concerned. You can google it, however.

Perhaps I should re-phrase my previous post in which it sounded as if it was fact that Knuth had something to say about this--it was another who claimed so. I would have to read it myself to know for certain.

pseudorandom21 166 Practically a Posting Shark

Well the way you have used them doesn't make much difference from what I saw, but it certainly could cause a problem if you didn't know it was a new scope.

pseudorandom21 166 Practically a Posting Shark

It can be done but it's usually not easy, nor is it intuitive. I have "scraped" a website with C++, which means downloading a copy of the web page's HTML.

For your particular problem, wouldn't ftp be easier to use than HTTP ?

Scraping is a bad way to do it, but I did it...
with HTTP you'll connect to www.mysite.com then send a request for the page you want, it may look something along the lines of (but probably not exactly) this:
GET /check/check.txt

Anyway, unless you want to use some libraries for HTTP automation/stuff then you will be reading a lot of HTTP specification, and most of it doesn't tell you what you need to know.

That said, I highly recommend not scraping the web page. I haven't used FTP but I have written an SMTP client, and a POP client, and it is my thinking FTP is quite do-able. You may want to use a third party library for FTP also.

There are thousands of libraries for C++ (lucky us). Also, using a library will most likely save you a lot of time.

pseudorandom21 166 Practically a Posting Shark
{
cout << "Here is your official receipt: " <<endl;
}

Those curly braces (the '{' and '}') define a new local scope. It seems hard for me to define "scope" for you, I really can't think of a good definition for it. But google can... Beloved Google.

pseudorandom21 166 Practically a Posting Shark

After a google search I found out that Knuth (the programming book author) has in his second edition something like this (this is my implementation):

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>

int main()
{
	typedef unsigned int uint;
	const uint cSize = 99999;
	uint data[cSize] = {0};
	srand(uint(time(nullptr)));
	std::for_each( data, data+cSize, [](uint &n) {
		//
		n = rand();
	});

	double M = 0.0;//,
		//S = 0.0;
	for(uint i = 0; i < cSize; ++i){
		//
		M += (data[i] - M)/(i+1);// <<<----ATTENTION HERE.
		if( (std::numeric_limits<double>::max() - M) < 1000 )
			std::cerr << "WARNING!!!" << std::endl;
	}
	//std::for_each(data, data+cSize, [](uint n){
	//	std::cout << n << ' ';
	//});
	std::cout << M << std::endl;
	std::cin.get();
}

I used a lambda or two so if you want to use it with an older compiler you will need to make adjustments.

pseudorandom21 166 Practically a Posting Shark

I'm just wondering, is there a way to compute the arithmetic mean without using a summation like the normal algorithm does?

pseudorandom21 166 Practically a Posting Shark

Place code between the code tags, which are [ code] and [ /code] (without the space)

I would consider using a matrix to represent the seat data, and a structure holding the information for each seat.

matrix = 2 dimensional array

For the letter-index system, I would simply create an alphabet in the code, like so: const char *alphabet = "ABCDEFGHIJ"; The index of the letter in the array(alphabet) can be used as the index, and it will allow you to logically use seats like "A1" and "J2".

of course you may opt to do it totally different, you don't have to listen to every fool willing to type ;)


I'm also wondering why you opted to define a new scope for various portions of your main() function.

pseudorandom21 166 Practically a Posting Shark

I'm quite aware of QT and the others. I want to learn to use win32 effectively, just for the added skill.

pseudorandom21 166 Practically a Posting Shark
bubblesort(array[],size);

to bubblesort(array,size);

pseudorandom21 166 Practically a Posting Shark

Oh and that loops 201 times, starting at zero and continuing until = 200 = 200 + 0 (0 counts as one also) thus 201.

pseudorandom21 166 Practically a Posting Shark

I don't think this is correct, I've never seen anyone try to do this, either:

inFile.read((char*)&Value1, sizeof(string));

It just looks like a really bad idea, with the string not being an array of characters and all, what with the functions and what-not in the class.

pseudorandom21 166 Practically a Posting Shark

I found this excellent video on one of Microsoft's websites: http://msdn.microsoft.com/en-us/ff728575

I'm really just wondering how to organize the window procedures for my Dialogs/Buttons/etc.

Would one normally after creating a dialog throw the window procedure into a new file? I don't like tiny bits of code in different files, so I decided to ask for another opinion.

As far as using Win32 goes, what does one need to know program code organization-wise?

pseudorandom21 166 Practically a Posting Shark

You can make a variable in findLowest static. Sorry for the delay, busy as usual.

pseudorandom21 166 Practically a Posting Shark

I think you're missing some program code, and tell us exactly what problems you are experiencing, and also what you're trying to accomplish.

pseudorandom21 166 Practically a Posting Shark

Don't be so hard on yourself.

http://msdn.microsoft.com/en-us/library/ms646307%28v=vs.85%29.aspx

if(nChar == static_cast<char>(MapVirtualKeyEx(wParam,MAPVK_VK_TO_CHAR,0)) )
{
//...
}

I don't have a solution if that isn't the problem, unfortunately. I'm sure someone can help, however.

Have you tried stepping through it with the debugger to see what "nChar" or "m_check" actually contain?

pseudorandom21 166 Practically a Posting Shark

In win32 it is in either LPARAM or WPARAM, I've forgotten (don't use it)--so, I'll happily google that for you so that we both learn. I'm hoping you can apply this to your MFC application.

Ok, MSDN (which you should be using as a reference) says: http://msdn.microsoft.com/en-us/library/ms646276%28v=vs.85%29.aspx

WPARAM is the character code of the key. I think it means the virtual key code for the key, not the hardware scan code (it should have specified if it was).

Does that help?

pseudorandom21 166 Practically a Posting Shark

I have to stand up for Ivor Horton's Beginning Visual C++ series. The 6.0 version of his book has served me well. The 2010 edition teaches C++/CLI as well as C++. I think he has a title that is pure C++, but you may want to look around for it because I don't know the title.

pseudorandom21 166 Practically a Posting Shark

Oh sorry, I didn't know you were calling srand() every time you wanted a new random number.

call srand() once for the life of the program.

pseudorandom21 166 Practically a Posting Shark

I would suggest RAII -- resource acquisition is initialization.
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

In which, you create a class that will manage your resource acquisition (allocating your matrix on the heap), and when it goes out of scope it's deleted safely, even if exceptions occur.

An example of my idea:

#include <iostream>
class MemoryManager
{
  char *chunk;
  //Constructor
  MemoryManager() : chunk(NULL)
  {
    chunk = new char[4086];//<-- allocate.
  }
  //Destructor
  ~MemoryManager()
  {
    delete [] chunk;
  }
};

int main()
{
  MemoryManager m;
  std::cout << "Memory is allocated; press ENTER." << std::endl;
  std::cin.get();
  return 0;//<-- memory is de-allocated at program end.
}

I haven't tested it, but it's so trivial I don't expect any bugs.

It works because the class that allocated all the memory is on the stack, and when it goes out of scope the destructor deletes the heap allocated memory.

pseudorandom21 166 Practically a Posting Shark

One more question - should I try to create the matrix only once at the start of the program and then delete at the end while resetting the pointers back to NULL at the start of each iteration?

If you set a pointer which is pointing to something to NULL before you delete it, that is a memory leak. You may do so after deleting it, however.

Please review the process I have posted on one of my earlier posts, and I have updated my previous post with information about the const pointer to data. Though there is really only one pointer being copied, and it's a pointer-to-a-pointer.

Here is a revision to your function:

void populateMatrix( myClass ** const & inMyMatrix, int inIteration, int inXDimension, int inYDimension )
{

	int populateNumber = 0;

	for (int i = 0; i < inXDimension; i++)
	{

		for (int j = 0; j < inYDimension; j++)
		{
			// Here I want to populate inMyMatrix[i][j] with inIteration * 20 + populateNumber,
			// but I'm not sure how I refer to inMyMatrix
			//
			populateNumber++;
			inMyMatrix[i][j].setValue(inIteration * 20 + populateNumber);
			//I'm so tired of this...
			//Ok, so the order of operations for programming in C/C++ dictates
			//that the inIteration * 20 will be evaluated BEFORE adding populateNumber.
			//Is this the desired effect?
		}

	}

}
pseudorandom21 166 Practically a Posting Shark

Actually NULL is in the <cstddef> header--C standard defines.

and on my previous example I forgot to intialize the pointer to NULL, so: myClass** myMatrix = NULL; Otherwise it's pretty perfect, and won't leak memory. Congrats.

I did forget to ask why you're passing the pointer-to-pointer by reference, do you intend to modify the actual pointer? That would be a massively bad idea that would lead to leaking more memory.

Nothing is copied when you pass a pointer to some data by value except the pointer--which is probably ideal unless you want to use a const reference.

--edit-- only one pointer is copied.

Here is the syntax: void populateMatrix( myClass ** const & inMyMatrix, int inIteration, int inXDimension, int inYDimension ) That is a const reference to a pointer-to-pointer, it doesn't allow the person to modify the actual pointer (the only copy you have) that points to all your data.

There are two ways to use const, one is for constant data, the second is for constant pointers. Here I have used a constant pointer so that no one uses pointer arithmetic and destroys the only pointer you have to all that allocated memory.

Hope it all works out now.

pseudorandom21 166 Practically a Posting Shark

When I write the program to just create the matrix and then delete the matrix, it takes a while to delete it unless I set the pointers to null *after* the new statement, but I don't fully know why.

You have to make sure that you don't lose a pointer to an object you allocated with "new", otherwise it will be impossible to delete it (free the memory) and you will have a memory leak.

My guess is that the compiler optimizes the allocation/memory leak sequence so that it doesn't even allocate any memory--because it would be impossible to use the allocated memory anyway.

Typically one would want to use this sequence:

//Create a pointer set to NULL/nullptr
long *lp = NULL;
//Allocate memory with "new", which means the pointer now equals the
//address of the newly allocated memory.
lp = new long;
//...Use the variable/class instance.
//

//Delete the allocated memory, and set to NULL/nullptr.
delete lp;
lp = NULL;

Unfortunately what we've done doesn't allocate your pointers on the stack, I really don't see how we could. C++ doesn't take too kindly to dynamically allocating stuff on the stack. There are compilers that allow that, however.

pseudorandom21 166 Practically a Posting Shark

Anybody feel like checking out the TR1 random number generation facilities? I think it will let you specify a larger range.

pseudorandom21 166 Practically a Posting Shark

Question #1. It's a C++ template, which is a powerful feature.
Question #2. You have two variables with the same name in the same scope. That's a no-no in every programming language I know of.

pseudorandom21 166 Practically a Posting Shark
int populateNumber;

should always be (imo) : int populateNumber = 0; Try this on for size:

int main()
{

	const int iterations = 10;
	const int xDimension = 4;
	const int yDimension = 5;

	for (int i = 0; i < iterations; i++)
	{

		// Create and initialize myMatrix
		myClass::numberOfValuesInMatrix = 0;

		myClass **myMatrix = nullptr;//<-- I tend to use myClass *myMatrix[]
		myMatrix = new (myClass*[xDimension]);//Array of pointers (which point to pointers)
		//as of now there are xDimension # of pointers (which point to pointers) in "myMatrix".

		for(int m = 0; m < xDimension; m++){
			myMatrix[m] = nullptr;
			myMatrix[m] = new myClass[yDimension]();//<-- special attention here.
			//Now you have an array of pointers that point to "arrays" of myClass's.
			//or if it's easier to think about, an array of pointers that point to other pointers (which are pointing to arrays).
		}

		populateMatrix( myMatrix, i, xDimension, yDimension );

		// Delete
		for (int i = 0; i < xDimension; i++)
		{
			delete[] myMatrix[i]; // Do I not have to cycle through the y dimension and delete those pointers?
		}
		delete []myMatrix;//<-- deleting other dimension.
		//depending on how you think about it, x and y can become quite confusing.  But no, you are deleting it all.

		myClass::numberOfValuesInMatrix = 0;

	}

	return 0;

}

If I'm not mistaken, you were trying to create an array of pointers to pointers, then the pointers to pointers in turn point to arrays of myClass's.

It's kind of like making a vector of vectors:

vector< …
pseudorandom21 166 Practically a Posting Shark

myMatrix[j] = new myClass[yDimension]; // "error C2512: 'myClass' : no appropriate default constructor available"

// Set the pointer to NULL - is this necessary?
myMatrix[j] = NULL;

You should set it to NULL before allocating memory, and after deleting the memory. No that's not necessary there.


you could define nullptr yourself--or switch to Visual Studio 2010, which supports "nullptr", "auto", lamba functions, new random number generation facilities, rvalue references, and maybe more.

auto f = []() { std::cout << "Hello C++0x TR1" << std::endl; };
f();

College students can get Visual Studio 2010 Professional for free at: www.dreamspark.com

pseudorandom21 166 Practically a Posting Shark

I usually use std::getline, and yes it's true it returns the istream object.

I commmonly do this:

string inputLine;
while( getline(inFile,inputLine) )
{
//... Process Line
}
pseudorandom21 166 Practically a Posting Shark

There is most likely a warning level you can set to have the compiler only display more critical warnings.

http://www.cplusplus.com/reference/string/getline/

pseudorandom21 166 Practically a Posting Shark

Using Visual Studio the exception class has a constructor overload with a C string as it's parameter. G++/GCC do NOT have that overload.

So blame Microsoft's compiler, then convert your exceptions to std::string.

The std::exception doesn't have the overload that has a const char * as a parameter on GCC/G++ compiler.

So if you want your exception throwing code to compile you will have to convert from the std::exception type to std::string or something similar.

Please, please, read what I've written.

pseudorandom21 166 Practically a Posting Shark
pseudorandom21 166 Practically a Posting Shark

I'm not a 3D expert, but I would find an accurate timer, and use it. For instance, on Windows you could use this: http://msdn.microsoft.com/en-us/library/ms724408%28v=vs.85%29.aspx

or on this page, the section "The following functions are used with high-resolution performance counters."
http://msdn.microsoft.com/en-us/library/ms725473%28v=VS.85%29.aspx

pseudorandom21 166 Practically a Posting Shark

(get it? no?.. nvm)

Yes.

If you're assigning a pointer the address of a stack allocated variable you need worry about when that variable goes out of scope, it will be destroyed! Then your pointer doesn't point to anything, and you will get some bad seg-fault type error messages at run time (meaning the program crashes).

With dynamic allocation it is common to leak memory, which when done to excess can cause your application to crash also. I only don't recommend dynamic allocation because you must keep track of the pointer and properly delete it, and with your current ideas a smart pointer is totally superior for that.

But in theory/practice you could copy an array of pointers to stack allocated objects and use them etc. As long as you make sure those variables don't go out of scope...

Or you could dynamically allocate and delete them.

smart pointers automatically delete the dynamically allocated variable when it goes out of scope.

The standard library has a smart pointer type, it's the std::auto_ptr<> BUT you can't put those in the STL containers for some lame reason. Thus, many opt to use the boost library's boost::shared_ptr<>.

I feel it is also important to note that programs often have limited stack space--with a limit of around 1 MB being common (as far as I know). Dynamically allocating memory uses the "heap" instead of the "stack" which will give you a much greater amount of memory …

pseudorandom21 166 Practically a Posting Shark

usingstd: :cout:
usingstd: :cin:
usingstd: :end1:
usingstd: :setw:

Surely you meant:

using std::cout:
using std::cin:
using std::endl:
using std::setw:

But since your program is so small it would be wise to: using namespace std; !
This shall not pass:

cout << end1 << end1;

It is "end" "L"

cout << endl << endl;

And finally the syntax for the do-while loop is:

do{
//...stuff
}while( /* condition */ );

So this needs to be a curly brace/bracket/{

do(

pseudorandom21 166 Practically a Posting Shark

Using Visual Studio the exception class has a constructor overload with a C string as it's parameter. G++/GCC do NOT have that overload.

So blame Microsoft's compiler, then convert your exceptions to std::string.

also this is absolutely WRONG!

void main()


Use instead

int main()

Please read here, on the creator of C++'s website about "void main()"
http://www2.research.att.com/~bs/bs_faq2.html#void-main

pseudorandom21 166 Practically a Posting Shark

If your C++ code consists of functions in a header file, then include the header file in the form you wish to use it in, and call the functions.

If your C++ code consists of class/es in a header file, then include the header
file and use the class.

I don't know why, but often times C++/CLI forces me to use dynamic memory allocation for classes:

class myclass
{
 int i;
};

//....
//in C++/CLI code:
myclass *m = new myclass();
//..use 'm'
delete m;
pseudorandom21 166 Practically a Posting Shark

Microsoft Visual Studio 2010 file. If you can re-build the project and link your runtime to the .exe statically that should fix it. (change an option in the project settings)

Otherwise, you can try putting the debug dll in the same folder as the .exe, or one directory above it because Visual Studio is weird like that.

MSVCP100D.dll
it is my guess another version of this file exists with the name:
MSVCP100.dll
which is not meant for the debug build of the application.

pseudorandom21 166 Practically a Posting Shark

in this header file are useful character manipulation functions: http://www.cplusplus.com/reference/clibrary/cctype/

and on a random side note, I would set the loop up like this:

while( fin.get(c) )
{
 if( c == '\n' || c == '\r' )//<-- not guaranteed to work.
  lines++;
//...

}

\r is the carriage return, which you may have forgotten about, or never used.
\n is the line feed, which is common on my Windows operating system.

pseudorandom21 166 Practically a Posting Shark

may want to initilize the static variable to 0 to start with.

It will have a positive value while instances of the class exist, otherwise 0.

pseudorandom21 166 Practically a Posting Shark

Well I'm glad to know you appreciate it, and it's always good to include sources. But, the point was for you to learn. Anyway, keep up the good work and try to learn how pointers work.

pseudorandom21 166 Practically a Posting Shark

Probably some input left in the stream. There are tutorials for avoiding this. Which is probably the best idea if you want to know what's going on.

Otherwise you can use my method:

int someInt = 0;
cin >> someInt; //<- if the user bunks this up and
//enters say a letter, cin will enter fail state, and there
//will probably be data left in the buffer--which happens in other
//ways also.
//so:
cin.sync();//<-- ignore anything left in the stream.
cin.clear();//<-- clear error bits.

See here for more info: http://www.cplusplus.com/reference/iostream/istream/

pseudorandom21 166 Practically a Posting Shark

I don't expect to be wasting my time, so I'll try to teach you a bit.

In your original code:

void Password()
{
		char pass[20];//array of 20 char variables.
		cout << "Password: ";
		cout << "\n";
		cin.get(pass[20]);//<-- as mentioned before,
//that line is calling the single character overload of the get()
//function of the istream class, of which the class instance 
//(variable, if you must)
// "cin" is an instance of.
//To see the available overloads please refer to the reference
//I posted earlier: http://www.cplusplus.com/reference/iostream/istream/get/
//Near the top of the page, in green text is the overload you are calling:
// istream& get ( char& c );
//Note, that you are calling this overload by specifying an index
//of the array, being [20] (which doesn't exist, 19 is the last as previously noted).
//by subscripting, i.e., [ ] the array you are specifying that you want
//to access a single element!

//I hope you know how pointers work, if not I don't think you will
//understand this fully.
//Because of the way pointers work, and the fact that in memory an array is
//allocated contiguously (think of a bunch of boxes in a line next to each other)
//the name you have given the array is implicitly a pointer to it's base,
//meaning, the pointer name points to the first element of the array,
//which is index 0.
//Thus, aha!  Each consecutive element can be accessed by incrementing the base
//pointer, or adding a number to …
altXerror commented: completely fixed my problem. +1