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

Where to ask? The proper forum, of course.

Advice? Of course.

Although you don't seem like the type, don't ask us to write code for you. Meaning, you have to show some effort to get help. Post the code you have, and tell us what you're having problems with.

As long as we see some effort on your part the users are usually glad to help.

pseudorandom21 166 Practically a Posting Shark

1 : C++ was my first programming language, it takes a while (a long time), heh that "steep learning curve" thing really doesn't mean it gets difficult to understand. But be prepared to put some time into it.
2 : I think it is, but I'm not a game programmer either. Like frogboy said, it will take effort to make that seemingly trivial game. As far as I know C#/Java isn't used for many blockbuster games--but that may change in the future.
3 : Donnow really, but "xcode" comes to mind.
http://developer.apple.com/technologies/tools/xcode.html
May also look at: http://developer.apple.com/

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

http://msdn.microsoft.com/en-us/library/bb525388(v=vs.85).aspx

Try testing the return value. There is also an example on that page.

pseudorandom21 166 Practically a Posting Shark

Will the std::stringstream convert the portion you're working with to __int64 ?

pseudorandom21 166 Practically a Posting Shark

hmm, You must not be aware that there are thousands of free C++ libraries available.

Alternatively your Operating System's API may actually support playback of MP3 sound, otherwise google a C++ sound library that meets your needs.

pseudorandom21 166 Practically a Posting Shark

-Duplicate.

pseudorandom21 166 Practically a Posting Shark

Depends on what Operating System you are using.

For Windows: http://www.microsoft.com/express/Windows/

pseudorandom21 166 Practically a Posting Shark

You need to use the .c_str() member of the std::string class to generate a NULL-terminated C-style "string" from the memory the std::string class is managing for you.

I would also suggest a polymorphic approach to parsing expressions like that, specifically using polymorphically a member function to return the result of a simple (what I will call) "term" of the form: n * b

ex:
3 * 5
or
1235 + 41236
or
-1000 - 342345

etc.

But then again, you don't have to listen to every fool willing to type--and I don't even know that's what you're doing.

pseudorandom21 166 Practically a Posting Shark

http://www.boost.org/doc/libs/1_46_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety

This section somewhat confused me, in my code I have a matrix of shared_ptr's pointing to an entirely thread-safe class.

But the shared_ptr documentation says it is only as thread-safe as the built-in C++ types. Does this mean that if I read/write to my thread-safe class using shared_ptr's at the same time it won't work?

To help illustrate, say I have a shared_ptr pointing to an instance of my thread-safe class, and a function which returns a new shared_ptr pointing to the same instance of my class.

Can I use the new shared_ptr to access my class without worry, (assuming the instance won't be destroyed)?

pseudorandom21 166 Practically a Posting Shark

I'm not sure I agree with finding code on the internet and trying to use it.

The way for you to understand it is to write your own code. If you run into problems while trying to do your own homework, please let us know and we'll kindly try to help you.

pseudorandom21 166 Practically a Posting Shark

What happens when you do:

char text[20];
cin >> text;

??

I really don't know, but I think it will allow someone to enter too many characters and 'sploit the program.

const std::streamsize BUFFER_MAX = 1024;
	char buffer[BUFFER_MAX] = {0};
	std::cin.getline(buffer,BUFFER_MAX,'\n');
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 hate to spring this kind of things on you, but if you expect some Americans to look at your code (which I am a native speaker of), you may want to read/write it like us too.

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

I don't think there is a standard way to do this (if I'm wrong I would like to know) so you will probably have to rely on the operating system. If you're using Windows/Linux the exact functions will vary.

Windows:
http://msdn.microsoft.com/en-us/library/078sfkak(v=vs.80).aspx

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

I think he needs to know how to dynamically allocate the array...

char *buffer = NULL;//<-- good style dictates initializing to nullptr.
buffer = new char[1024];//<-- array of 1024 characters.
//use array with familiar notation
delete [] buffer;//<-- delete the allocated memory so you don't "leak" it.
buffer = nullptr;//<-- good style.  delete doesn't do this for you.

Nevermind.

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

I'm taking a look at some of the code, my initial thoughts on your first problem are that the file stream has error bits set that need cleared.

Firstly as a matter of good style let's initialize your char array to '\0'. char fname[30] = {'\0'}; What this code does is ensure initializing the first element to '\0', and the way C++ works means it will zero the rest of the elements of the array that were not specifically initialized.

It appears the errors is indeed un-cleared file stream errors.

if (!fio)
			{
				cout << "File does not exist, try again? (y/n) ";
				again = getYesNo();
				cin.clear();
				cin.ignore();
				fname[0] = '\0';
			}

"fio" likely has error bits set that need be cleared, just like cin.


Hopefully this will make clear the issue:

if (choice == 'Y')
	{
		cin.clear();
		cin.ignore();
		do 
		{
			fio.clear();//<-- clear error bits.
			cout << "Enter the name of the existing file: ";
			cin.getline(fname, 30);
			fio.open(fname, ios::out | ios::in | ios::binary);//<-- set error bits on error.
			if (!fio)
			{
				cout << "File does not exist, try again? (y/n) ";
				again = getYesNo();
				cin.clear();
				cin.ignore();
				//As a matter of good style let's zero the array.
				memset(fname, 0, 30);
			}
		}while (again == 'Y' && !fio);//<-- test for error bits.
	}

Looks like this line was neglected:

fio.open(fname, ios::out || ios::binary || ios::trunc);

fio.open(fname, ios:: in | ios::out | ios::binary | ios::trunc); Some stuff is still left in your …

cousinoer5 commented: Thanks a lot for the help! :) +2
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

http://www.cprogramming.com/ //<-- not too bad.
http://www.cplusplus.com/doc/tutorial/ //<-- didn't use it, probably would now.
http://www.functionx.com/cpp/ //<-- not the best in my opinion.

pseudorandom21 166 Practically a Posting Shark

No you don't need global variables you can pass by reference or pointer, but I would suggest making a variable "static".

http://msdn.microsoft.com/en-us/library/s1sb61xd(v=vs.80).aspx

Note that the "static" keyword may behave differently than you expect in classes.

ex:

int CurrentTotal(int n)
{
  static int total = 0;
  total += n;
  return total;
}
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

Do not use

void main()

use instead

int main()
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

Place your code between [code] and [/code]

pseudorandom21 166 Practically a Posting Shark

There are infinite ways to do it.

Example of a C++ container template in the C++ STL: http://www.cplusplus.com/reference/stl/list/


Linked list information:
http://www.codeproject.com/KB/cpp/linked_list.aspx
http://www.functionx.com/cpp/articles/linkedlist.htm
http://richardbowles.tripod.com/cpp/linklist/linklist.htm


First of all you may benefit from deciding how you want to implement your list before you do so.

pseudorandom21 166 Practically a Posting Shark

You have to attempt it, and if you run into trouble we may offer some help. Basically we don't do your homework for you.

I will help you with this at least, if 'n' grows even slightly large you will need a very large data type to store the sum. I would consider for most systems the "unsigned long long" type.

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

The seg fault (in my honest opinion) is happening because you are trying to use a pointer that points to either, 1. garbage, or 2. nothing. Better to point to nothing.

We programmers have modern IDEs to help us debug our programs, and for the most part we probably use them.

If you're using Visual Studio you can hit "F5" to start debugging your program--but you will want to change the project to "debug" mode.

You can set breakpoints in which you want the execution to be halted so that you can examine the contents of variables that are in scope.

If you don't debug in "debug" mode you may not be able to examine the contents of variables while it's executing.

Almost forgot, but if you allocate ANYTHING with the keyword "new" it must be deleted with the keyword "delete". Maybe I've overlooked where you deleted what you allocated, but I didn't see it anywhere.

Smart pointers are almost always preferable to keeping track of an array of pointers.
http://www.boost.org/doc/libs/1_45_0/libs/smart_ptr/shared_ptr.htm

If you accidentally call "delete" on a pointer that points to some random memory address (which they do by default unless you initialize it to NULL) it will probably cause a seg-fault.

Thus the guidelines above are suggested (by me).

events[size]=new Event(month,day,year,activity);