pseudorandom21 166 Practically a Posting Shark

It doesn't "send" anything as far as I know, and if it does, it's probably dependent on the implementation--which you shouldn't concern yourself with.

It "returns" an iterator to the first element in the vector container.

For example:

std::vector<int> myVec(10,7);
std::vector<int>::iterator it = myVec.begin();
for( ; it != myVec.end(); ++it)
{
  std::cout << *it << std::endl;
}

You may want to brush up on iterators.

pseudorandom21 166 Practically a Posting Shark

Lambdas are awesome.

auto lam = [](const char *str) { std::cout << str << std::endl; };
lam("Hello World!");
pseudorandom21 166 Practically a Posting Shark

Is "stateB" a constant? The compiler may be whining that you are trying to initialize the array with dynamic data.

pseudorandom21 166 Practically a Posting Shark

I think that happens when an exception is thrown that isn't caught. Had that message from a VS2008 app once before.

pseudorandom21 166 Practically a Posting Shark

I see this all the time, and I hope by me explaining it, will make it clear to you.

After creating an array like so: char buffer[10] = { 'a','b','c'}; when you use the operator[] ( [ # ] ) you are accessing a SINGLE ELEMENT. No matter how you try to twist the meaning of using the operator[] on a simple array, it always does the same thing.

This is accessing a SINGLE element of the array, and if I did this: std::cout << buffer[1]; it would access the second element of the array, the second character. It would print 'b'.

The operator[] is NOT magic.

Pointers may seem like magic, but they aren't either. In fact, when I learned to program and had the epiphany that nothing about the computer is magic I was also disappointed.

A C style string (sometimes called a C string) is an array of char's with the last character set to 0, or NULL, or '\0'. The program will process characters in a C string until the terminating NULL character is encountered, this avoids needing to specify the length/size of a string. Thus an algorithm can simply process characters until the character NULL is encountered. This is very important for large strings. Variable length strings are used. The string can occupy a part of, or all of (minus the NULL) a character array.

Pascal strings were limited by a value specifying the length, please see this wikipedia …

pseudorandom21 166 Practically a Posting Shark

I do that all the time, except using a Mutex. I'm extremely new to C# and only today learned of the "lock" statement.

From what I've read about multi-threading in C# you may not want your _Status to be static. I searched google again and couldn't find the exact page on it. Remember I'm still new to this C# business. The readonly on the _LockThis puzzles me also.

pseudorandom21 166 Practically a Posting Shark

Okay, I used code blocks with the GCC compiler and this works for me:

#if       _WIN32_WINNT < 0x0500
  #undef  _WIN32_WINNT
  #define _WIN32_WINNT   0x0500
#endif

#include <windows.h>

int main()
{
    ShowWindow(GetConsoleWindow(),SW_HIDE);
    Sleep(5000);//Sleep so I can check the task manager for the process.
    return 0;
}

It works inside the editor and outside of it, despite the editor making you press any key.

You can, of course, show the window again at the end of the program.

My best advice to you is to use the right compiler switch to make the console window not appear at all.

pseudorandom21 166 Practically a Posting Shark

using the namespace "std" for string?

pseudorandom21 166 Practically a Posting Shark

right click your taskbar and select "Task Manager", go to the "Processes" tab, and kill the process.

Really, you should find the compiler option to not create the console window--it will avoid trouble like that.

pseudorandom21 166 Practically a Posting Shark

Not really, ya just need to get a handle to the console window somehow.
http://msdn.microsoft.com/en-us/library/ms683175(v=vs.85).aspx

Okay, I think I see the problem...

Remarks

To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the Windows Headers.

pseudorandom21 166 Practically a Posting Shark

If you are using Windows it's pretty simple, but not exactly guaranteed to not "flash" a console window for a moment.

What sfuo meant is you can tell your compiler to not spawn the console window. It's a compiler switch.

Now, this is the "dirty" way...

#include <Windows.h>

int main()
{
	HWND windowHandle = GetConsoleWindow();
	ShowWindow(windowHandle,SW_HIDE);
}
pseudorandom21 166 Practically a Posting Shark

If I'm understanding the problem correctly the solution is pretty simple.

want all your "words" in the string in different strings or something?

#include <iostream>
#include <string>
#include <sstream>
#include <vector>

typedef unsigned int uint;

//Returns, Num. words.
uint getWords(std::string &in, std::vector<std::string> &words){
	uint count = 0;
	std::stringstream ss(in);
	std::string currentWord;
	while( ss >> currentWord ){
		words.push_back(currentWord);
		count++;
	}
	return count;
}

int main()
{
	std::string commandData = "GET all_my_data IN all_the_base base... base.. base";
	std::vector<std::string> words;
	uint wordCount = getWords(commandData,words);

	std::cout << "Word Count: " << wordCount << std::endl;
	for(std::vector<std::string>::iterator it = words.begin(); it != words.end(); ++it){
		std::cout << *it << std::endl;
	}
}

Really it can be reduced to:

std::stringstream ss(someString);
std::string temp;
while( ss >> temp )
{
//..
}
WaltP commented: If he can't use a STRING yet, how can he use a VECTOR? -3
pseudorandom21 166 Practically a Posting Shark
pseudorandom21 166 Practically a Posting Shark

Your teachers don't care what technologies you use for that? That seems ood...

pseudorandom21 166 Practically a Posting Shark

I don't have a whole lot of experience with those, but in my opinion you will alienate a LOT of windows users. If you use some kind of messed up "build" system, will you port your application to windows? or will you require another download to install. End users hate dependencies like this.

pseudorandom21 166 Practically a Posting Shark

You will need the debug DLLs for the debug version and the release DLLs for the release version.

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

Very helpful, I never knew. That's why we communicate. :D

pseudorandom21 166 Practically a Posting Shark

No it isn't.
http://www.cplusplus.com/reference/clibrary/cctype/toupper/

Are you using Visual Studio? What version?

Well a quick (possibly misleading) google search claims C library stuff is meant to be in the std namespace, but visual studio sucks and it isn't.

My thoughts are:
http://www.cplusplus.com/reference/std/locale/toupper/
http://www.cplusplus.com/reference/clibrary/cctype/toupper/

Only version of std::toupper provided is:

template <class charT>
  charT toupper ( charT c, const locale& loc );

Could someone make sure std::toupper(int) exists on other compilers? (G++)

Microsoft always likes to have small differences with other compilers, for instance on G++ I don't think there is a std::exception constructor overload that accepts a C string.

pseudorandom21 166 Practically a Posting Shark

Sorry, I thought it would be obvious it's not in the std namespace.

pseudorandom21 166 Practically a Posting Shark

Be able to take advantage of every feature of C++, including the STL.

Study Algorithms, Data structures, and other misc. Computer Science stuff--like Artficial Intelligence, etc.

For instance a DFA/NDFA/FSM comes in REAL handy sometimes: http://en.wikipedia.org/wiki/Finite-state_machine

Calculus too.

pseudorandom21 166 Practically a Posting Shark

In your example:

std::tolower(*end)

tolower is in <cctype> and is a C function.

pseudorandom21 166 Practically a Posting Shark

I think the pages for the functions you're using here will help: http://www.cplusplus.com/reference/stl/list/

pseudorandom21 166 Practically a Posting Shark

Does this work properly given the master.dat input file?

#include <iostream>
#include <fstream>
#include <string>
#include <list>

typedef unsigned int age_type;
//Record type
struct Record{
	std::string name;
	age_type age;
	Record(std::string fname, age_type howOld) : name(fname), age(howOld) {}
	bool operator<(const Record &rhs){
		return this->age < rhs.age;
	}
	std::istream& ReadLine(std::istream &inFile){
		return inFile >> this->name >> this->age;
	}
};

//Convenience function.
std::istream& ReadLine(std::istream &inFile, std::string &word, age_type &age){
	return inFile >> word >> age;
}

//Entry-point
int main()
{
	using namespace std;
	const char *fileName = "master.dat";

	list<Record> inputList;
	fstream inFile(fileName,ios::in);
	if(!inFile.is_open()){
		cerr << "File didn't open.\n";
		return 1;
	}
	string word;
	age_type age = 0;

	while(ReadLine(inFile,word, age)){//<-- using convenience function.
		cout << word << ' ' << age<< endl;
		inputList.push_back( Record(word,age) );
	}
	inFile.close();
	inputList.sort();

	cin.get();
}
pseudorandom21 166 Practically a Posting Shark

@nathanOliver, removing 132 got emily 99 to come back, any idea why ashley 83 is still being printed twice? She should only be printed once.

Yes it's an end-of-file bug because of the way you are reading from the file.

I would bet money on it.

pseudorandom21 166 Practically a Posting Shark

I tend to think it would be a problem with reading the file.

This will cause problems:

while(!Infile.eof())

Try instead:

std::string name;
unsigned long age;
while( inFile >> name >> age )
{
//.. use it.
}

Otherwise consult some file IO reference material.

pseudorandom21 166 Practically a Posting Shark

Copy everything to a new string and when you hit a '\n' insert "<br>" instead.

pseudorandom21 166 Practically a Posting Shark

For the 10 seconds to enter a password thing you will most likely want to start a new thread that waits for 10 seconds to grab some input.

pseudorandom21 166 Practically a Posting Shark

I noticed you have a lot of variables in one structure, I usually try to nest some structures like this:

struct CategoryOne{
int a;
int b;
std::string s;
};
struct CategoryTwo{
bool tf;
double d;
};
struct AllMyData{
CategoryOne catOne;
CategoryTwo catTwo;
};

I am only posting this because I think it may make all those variables easier to manage.

pseudorandom21 166 Practically a Posting Shark

If you intend to skip whitespaces I suggest you read using operator>>
In your original code you have both:

getline(inFile,str);
//and
inFile >> str;

Perhaps re-writing your loop condition to:

while(inFile >> str)
{

}

and the operator '>>' will read in one block of non-whitespace characters, or a "word" at a time.

pseudorandom21 166 Practically a Posting Shark

It sounds like the solution would be to pass the size of array along with the pointer to the array's base.

It seems very hard for me to tell exactly what you're having a problem with. So you have information in your add function that you need to pass to your print_ans() function? Could you point out what you're trying to give to the print_ans() function?

pseudorandom21 166 Practically a Posting Shark

Any reason for passing by pointer instead of by reference?

pseudorandom21 166 Practically a Posting Shark

You mean you're having trouble getting it to output 8 numbers per line?

void add(int binums[][DIM2], int ans[])
{
	const int OUTPUT_MAX_LINE = 8;
	int total = 0,
		carry = 0,
		i = 0,
		j = 0,
		outputCount = 0;

	cout << endl;
	for (j = DIM2-1; j >= 0; j--)
	{
		total = carry;
		for (i = 0; i < DIM1; i++)
		{
			total = total + binums[i][j];	
			ans[j] = total % 2;
			carry = total / 2;
		}
		if( outputCount < OUTPUT_MAX_LINE )
		{
			cout << ans[j] << ' ';
			outputCount++;
		}
		else
		{
			cout << endl << ans[j] << ' ';
			outputCount = 0;
		}
	}
}
pseudorandom21 166 Practically a Posting Shark

Wow I apologize about my previous post--It doesn't work as intended due to the unsigned type used.

I will have to revise my implementation.

for( size_t i = DIM1; i > 0; i-- )
{
  for( size_t j = DIM2; j > 0; j-- )
      ;//Use i-1, j-1.
}
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

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

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

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
bubblesort(array[],size);

to bubblesort(array,size);

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

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

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

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