147 Posted Topics

Member Avatar for sagar d

It's true. You can build games using C. But you can build better using C++. Object oriented design helps a lot when you model the game world, entities and entity interactions. Plus, there are very good libraries available to help. As for your code request, I guess there are a …

Member Avatar for imkj
-1
233
Member Avatar for learningcpp

[QUOTE=learningcpp]Can you please explain why is this working?[/QUOTE] Why shouldn't it work? I do it all the time :P In this case, the definition acts as a declaration too. [QUOTE=learningcpp]if I take of the friend from infront of the method name, it fails compiling[/QUOTE] Well, operator << is a binary …

Member Avatar for m4ster_r0shi
0
350
Member Avatar for Celtrix

It really isn't easy to say without seeing the contents of "user.hpp"... If I were you, I'd put cout statements in key places of the code in order to isolate the problem.

Member Avatar for Celtrix
0
351
Member Avatar for v_janssens

What you need is called dynamic memory allocation: [CODE]#include <iostream> using namespace std; struct Node {}; int main() { int num_n; cout << "Enter number of nodes:\n"; cin >> num_n; // Allocate memory dynamically Node * my_nodes = new Node[num_n]; for (int i=0; i<num_n; i++) { // Set values of …

Member Avatar for alwaysLearning0
0
215
Member Avatar for thecoolman5

What's wrong with this? [CODE]#include <iostream> using namespace std; int main() { double number1, number2; char operation; while (true) { cin >> number1; cin >> operation; cin >> number2; if (!cin) break; switch(operation) { case '+': cout << number1 + number2 << endl; break; case '-': cout << number1 - …

Member Avatar for thecoolman5
0
579
Member Avatar for TheLittleEngine

As mentioned above, the main use of constructors is object initialization. You may think that this is not an important job, but consider this -> You want to create a vector of 10 vectors of 10 ints and you want to assign the value 25 to all of them (the …

Member Avatar for Stefano Mtangoo
0
214
Member Avatar for SilentCoder

Check these out too: [url]http://en.wikipedia.org/wiki/INI_file#Accessing_INI_files[/url] [url]http://msdn.microsoft.com/en-us/library/ms724353.aspx[/url] [url]http://msdn.microsoft.com/en-us/library/ms724345.aspx[/url] EDIT: Though, your file doesn't seem to have the correct format... You may have to change it.

Member Avatar for m4ster_r0shi
0
11K
Member Avatar for theguitarist

[QUOTE=Narue]I challenge you to input a character with the value of 0 using cin. It's not as simple as you might think.[/QUOTE] Assuming I have a char variable declared, I can do this in one statement.

Member Avatar for m4ster_r0shi
0
189
Member Avatar for mic_mic

The problem is that your compiler doesn't know how to add/subtract complex numbers using operators +/- A simple solution is to define two functions for these operations... [CODE]//... cmplxNumber add_cmplx(const cmplxNumber & c1, const cmplxNumber & c2) { //... } cmplxNumber sub_cmplx(const cmplxNumber & c1, const cmplxNumber & c2) { …

Member Avatar for mic_mic
0
357
Member Avatar for sha11e

Piece of cake! Use SetForegroundWindow -> [url]http://msdn.microsoft.com/en-us/library/ms633539(v=vs.85).aspx[/url] [CODE]#define _WIN32_WINNT 0x0500 #include <windows.h> int main() { HWND hwnd = GetConsoleWindow(); int timer_1 = 0; int timer_2 = 0; int delay = 50; while (true) { if (timer_1 > 100) { if (GetAsyncKeyState(VK_ESCAPE) >> 15) break; timer_1 = 0; } if (timer_2 …

Member Avatar for m4ster_r0shi
0
1K
Member Avatar for pseudorandom21

It's an interesting topic, so I decided to investigate a bit. The program you wrote [I]does[/I] work with video games. However, don't forget that in a video game the whole window is redrawn many times a second. This means your rectangle is visible merely for some milliseconds. If you try …

Member Avatar for pseudorandom21
0
330
Member Avatar for airerdem

Don't use a list. Use a vector or a deque and std::sort. Useful links: [url]http://cplusplus.com/reference/stl/vector/[/url] [url]http://cplusplus.com/reference/stl/deque/[/url] [url]http://cplusplus.com/reference/algorithm/sort/[/url]

Member Avatar for mike_2000_17
0
139
Member Avatar for digital_ice7

Why don't you pass the array as an argument to the function instead? [CODE]//... void test(string a[5]) { a[0] = "Hello"; //... } int main() { string b[5]; test(b); //... }[/CODE]

Member Avatar for digital_ice7
0
601
Member Avatar for triumphost

[QUOTE=triumphost]How would I go about calling java in c++ or invoking it..[/QUOTE] I don't think you need to do that. Usually, a bot doesn't have access to the game's code. It only interacts with the game the same way a human would interact with it. That is, by getting visual …

Member Avatar for m4ster_r0shi
0
170
Member Avatar for nocloud
Member Avatar for btowne2
Member Avatar for Lerner
0
192
Member Avatar for dyingatmidnight

Excuse me, this is not homework, right? Why not do it the STL way? [CODE]#include <iostream> #include <string> #include <bitset> using namespace std; string atobcd(const string & ascii) { string ret; string::const_iterator cur_it = ascii.begin(); string::const_iterator end_it = ascii.end(); for ( ; cur_it != end_it; ++cur_it) ret += bitset<8>(*cur_it - …

Member Avatar for m4ster_r0shi
0
1K
Member Avatar for arshi9464

[QUOTE=arshi9464]how can i access a particular memory area using pointers?[/QUOTE] Why do you want to do this? What kind of memory area is this? Maybe there are OS API functions that do exactly what you want. For example, if you want to write a cheat engine on windows, you can …

Member Avatar for TrustyTony
0
151
Member Avatar for learningcpp

This is called padding and it is done by your compiler to improve access speed of the struct members. Useful link -> [url]http://en.wikipedia.org/wiki/Data_structure_alignment#Data_structure_padding[/url]

Member Avatar for mike_2000_17
0
174
Member Avatar for CPT

You shouldn't delete your buttons in your constructor. Do it in your destructor, using a for loop. The for loop in your constructor should look like this: [CODE]//... for(int bt_index = 0; bt_index < NrButtons; bt_index++) { File >> mask; //rading the mask File >> imag; //normal image File >> …

Member Avatar for m4ster_r0shi
0
160
Member Avatar for cheenu02

I may be wrong, but I think the OP wants to demonstrate that the value of the pointer is increased by 4 (or whatever sizeof(int) is in his machine) when he uses operator ++ on it. This should do it: [CODE]#include<stdio.h> int main() { int * p = (int *) …

Member Avatar for bajishareef
0
2K
Member Avatar for niggz

Yes, I believe the above will work. As for the other question... [QUOTE]Is there any way to write it like [ICODE]while( style!={"contain","defensive","counter"} ) {/*...*/}[/ICODE][/QUOTE] Yes, there is a way to do it like this: [CODE]#include <algorithm> #include <iostream> #include <string> using namespace std; const string allowed_styles[7] = { "contain", "defensive", …

Member Avatar for niggz
0
166
Member Avatar for PixelatedKarma

To add to the above, if you don't want to create a window, you can also use this -> [url]http://msdn.microsoft.com/en-us/library/ms646293(v=vs.85).aspx[/url]

Member Avatar for m4ster_r0shi
0
212
Member Avatar for airerdem

Are you sure the file exists and is in the correct folder? What do you mean by saying they do not work? Are you getting compilation errors, or is it something else? It would really help if you posted your code.

Member Avatar for airerdem
0
94
Member Avatar for mrnutty

Here's another one: [CODE]#include <iostream> struct B { virtual void print(const char * msg = "wtf? -.-") { std::cout << msg << std::endl; } virtual ~B() {} }; struct D : B { void print(const char * msg = "Hello, World!") { std::cout << msg << std::endl; } }; int …

Member Avatar for Moschops
0
144
Member Avatar for senergy

You can try opening it for reading and check if it's open. If it's not open, it doesn't exist. [CODE]//... #include <fstream> #include <string> //... std::string filename; //... std::ifstream fin(filename.c_str()); if (fin.is_open()) { /* file exists */ } else { /* file does not exist */ } //...[/CODE] Useful link …

Member Avatar for senergy
0
1K
Member Avatar for phalaris_trip

I recently stumbled upon an interesting pdf explaining how you can do OOP in C -> [url]http://www.planetpdf.com/codecuts/pdfs/ooc.pdf[/url] It uses structures like this one to hold the type information in a compact way: [CODE]struct Class { size_t size; void * (* ctor) (void * self, va_list * app); void * (* …

Member Avatar for MonsieurPointer
0
4K
Member Avatar for Tweekler

You are very close. You should set current to zero every time i changes, not just when it's big enough to become the current mode count. EDIT: You were closer than I initially thought...

Member Avatar for mrnutty
0
1K
Member Avatar for evaldaskowka

Check these out: [url]http://cplusplus.com/reference/clibrary/ctime/localtime/[/url] [url]http://cplusplus.com/reference/clibrary/ctime/tm/[/url]

Member Avatar for Ancient Dragon
0
220
Member Avatar for Tweekler

[QUOTE=your teacher]The list will be piped in from the command line and terminated with end-of-stream (^Z).[/QUOTE] This means that you can simply do it like this: [CODE]#include <iostream> #include <vector> int main() { std::vector<int> my_vector; int temp; while (std::cin >> temp) my_vector.push_back(temp); //... }[/CODE] When you reach the end-of-stream (CTRL-Z), …

Member Avatar for m4ster_r0shi
0
132
Member Avatar for dilequeno

Is using a vector a requirement? You could use a (multi)set and its upper_bound member function. If the data on the file is already sorted, you can use the global upper_bound function with a vector. Useful links: [url]http://www.cplusplus.com/reference/stl/set/[/url] [url]http://www.cplusplus.com/reference/stl/set/upper_bound/[/url] [url]http://www.cplusplus.com/reference/stl/multiset/[/url] [url]http://www.cplusplus.com/reference/stl/multiset/upper_bound/[/url] [url]http://cplusplus.com/reference/algorithm/upper_bound/[/url]

Member Avatar for L7Sqr
0
886
Member Avatar for Jsplinter

If you don't modify your initial vector after populating the second, I guess it's ok. Otherwise, both approaches (pointers and iterators) are problematic. BTW, there are ready solutions to this -> [url]http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/index.html[/url] EDIT: Also, if you use decide to use pointers, you probably need pointers to myClass, not to int …

Member Avatar for Jsplinter
0
5K
Member Avatar for KAY111

There are two problems: (1) m must terminate before n can use its output as input. (2) n doesn't terminate. These should work ok: [B]m.cpp[/B] [CODE]#include <iostream> using namespace std; int main() { int a=34, b=40; int count = 0; while(1) { if (++count > 10) break; cout << a …

Member Avatar for L7Sqr
0
173
Member Avatar for mirkuh

Well, in order to inline a function pointed to by a function pointer, the compiler must know (at compile time) which function the pointer points at when it's used. The compiler doesn't know that. Therefore, this code... [CODE]#include <cstdio> class CTest { public: inline static void StaticMethod(void) { printf("lalalalalalala\n"); } …

Member Avatar for JasonHippy
0
411
Member Avatar for AW8Dragon

Yes, but getting them in separate strings, the way they appear in the file, and then concatenating them the way you want is easier. EDIT: Too slow...

Member Avatar for m4ster_r0shi
0
120
Member Avatar for akhal

If you're getting a stack overflow error it means that your array is too big to be allocated on the stack. It has nothing to do with passing it to the function. Try using a dynamically allocated array instead. A std::vector<std::vector<double> > is a good alternative too. Also, this... [CODE]class …

Member Avatar for NathanOliver
0
419
Member Avatar for king03

The problem is here -> [ICODE]cin >> record[i].course;[/ICODE]. It should be [ICODE]getline(cin, record[i].course);[/ICODE]

Member Avatar for m4ster_r0shi
0
199
Member Avatar for m4ster_r0shi

I have two code snippets that involve recursive manipulation of std::strings. [B]code snippet 1[/B] [CODE]#include <iostream> #include <string> void print_stuff(int min_n, int max_n) { struct local { static void build_stuff( int min_n, int max_n, int cur_n, int cur_c, int max_c, bool inc, std::string & ret) { if (cur_c == max_c) …

Member Avatar for m4ster_r0shi
0
247
Member Avatar for merse

Maybe not the best way to do it, but it most certainly is an option: [CODE]#include <iostream> #include <set> template <class T> struct SetMaker { std::set<T> data; SetMaker & operator << (const T & element) { data.insert(element); return *this; } SetMaker & operator , (const T & element) { data.insert(element); …

Member Avatar for lcordero
0
2K
Member Avatar for Celtrix

The test should be [ICODE]if(argc == 1)[/ICODE]. [ICODE]argc[/ICODE] always is at least 1, as the first argument always is the command that invoked the program.

Member Avatar for Celtrix
0
174
Member Avatar for fatalaccidents

[QUOTE]I know I should pass it as a pointer, but for some reason it still doesn't seem to be doing anything.[/QUOTE] How do you do this? Could you post an example? Mind that you may have to pass the pointer by reference (or by pointer). Check this out: [CODE]#include <iostream> …

Member Avatar for fatalaccidents
0
250
Member Avatar for crapgarden

[B]Q1[/B] The semicolon (;) just indicates the end of a statement. It has nothing to do with the end of the string. When you use double quotes (") around text, your compiler kindly puts a null character at the end. [B]Q2[/B] phrase is an array of 13 chars. This -> …

Member Avatar for crapgarden
0
189
Member Avatar for M1n1m@l1$t
Member Avatar for UltimateKnight

It's an interesting approach, but the scoped color idea is a bit awkward... I would do something like this: [CODE]#include <iostream> #include <iomanip> #include <windows.h> struct Color { int color; Color(int color_): color(color_) {} Color operator + (const Color & other) const { return Color(this->color | other.color); } }; #define …

Member Avatar for UltimateKnight
0
235
Member Avatar for jackmaverick1

Try [ICODE]class Block * blocks[8] = nullptr;[/ICODE] in Cube.h and/or [ICODE]class Cube *cube;[/ICODE] in Block.h

Member Avatar for Arbus
0
127
Member Avatar for thecoolman5

You can't do that with PlaySound. If you want that kind of functionality you need a library like OpenAL or SDL or SFML etc...

Member Avatar for m4ster_r0shi
0
3K
Member Avatar for eman 22

Here's an example of how you can split the key in bytes and then use them to calculate the hash value, provided that the key is a primitive or a POD: [CODE]#include <iostream> template <class T> uint32_t hash(const T & key, uint32_t key_size, uint32_t table_size) { const uint8_t * bytes …

Member Avatar for m4ster_r0shi
0
614

The End.