c++

Storing and printing 10+ digit integer in c++

I'm using cout to print digits to the console. I am also storing values of up to 13+billion as a digit and doing computations on it. What data type should I use? When I do the following: int a = 6800000000; cout << a; It prints -1789934592. thanks. ...

TCHAR[], LPWSTR, LPTSTR and GetWindow Text function

So the GetWindowText is declared on MSDN as follows: int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount ); However for the code to work we have to declare the second parameter as TCHAR[255] WTitle; and then call the function GetWindowText(hWnd,Wtitle,255); The LPTSTR is a pointer to an array of tchar, so...

throwing an exception causes segmentation fault

Collection CollectionFactory::createFromMap(const std::string& name, const DataMap& dm) const { if (!Collection::isNameValid(name)) { const std::string error = "invalid collection name"; throw std::invalid_argument(error); } Collection c(name, dm); dm.initDataCollection(&c, true); return c;...

Socket programming Xp > Vista, Vista > XP

I am developing a program which sends images from one computer to another (similar to remote assistance without mouse/keyboard input). The two computers I use to test this are one Windows XP machine and one Windows Vista. I have the stationary XP machine directly connected to a router, and a laptop which is connected through wireless. ...

C++, Seg Faults, and Memory Management

I'm moving from Java to C++ and have really enjoyed it. One thing I don't enjoy is not understanding memory at all because Java used to do that for me. I've purchased a book : Memory as a Programming Concept in C and C++ - Frantisek Franek Are there some good sites for me to go and learn interactively about C/C++ and memory use (tuto...

Input asked for better programming practices

As I'm learning C++ I started implementing some common datastructures as a form of practice. The first one being a Stack (this was the first to spring in mind). I've done some programming and it's working, but now I need some input as to what I should do otherwise. Like deleting certain stuff or other pro tips. What should I do different...

Getting volume change notifications on Vista/7 (C++)

I'm trying to get notifications whenever the master volume changes on Windows Vista/7. This is the code I'm using: #include <audiopolicy.h> #include <audioclient.h> #include <mmdeviceapi.h> #include <endpointvolume.h> #include <windows.h> #include <shlwapi.h> #include <iostream> #include <Tchar.h> static const GUID AudioSessionVolumeCt...

Invalid conversion char to char* - Copying char in string array to another string array

Hi all, I'm a beginner in C++ Programming language. I wanted to write a program that take the alphabets in a string array called str, and copy it in a new array called str_alpha. And the same goes to numbers, the program copies it from str array to str_digit array. There's my humble code, it might be full of errors and stuff. But this...

initialize reference in initialization list

Hi, I was told the reference variable must be initialized in the initialization list, but why this is wrong? class Foo { public: Foo():x(0) { y = 1; } private: int& x; int y; }; Because 0 is a temporary object? If so, what kind of object can reference be bound? The obj...

c++, truncate a char array

Hello, I'm working on a project where I have a Time class and I need to format the time. void Time::FormatTime(char *string, unsigned int max_string_len) { ostrstream fd; ft << hour << ":" << minutes; cout << ft.str() << endl; } The user passes in a pointer to their string and the max length of the string and I need...

Static functions, inlining and templates?

I have a template class with a static function (see Connect function below). This template class is part of a 3rd Party lib (call it LibA). My code uses this lib and includes the header below since I need to use the template class. When I compile my lib without inline functions (-fno-default-inline with gcc) I get no problems. When I...

Creating a System::String object from a BSTR in Managed C++ - is this way a good idea???

My co-worker is filling a System::String object with double-byte characters from an unmanaged library by the following method: RFC_PARAMETER aux; Object* target; RFC_UNICODE_TYPE_ELEMENT* elm; elm = &(m_coreObject->m_pStructMeta->m_typeElements[index]); aux.name = NULL; aux.nlen = 0; aux.type = elm->type; aux.leng = elm->c2_length; aux....

Accessing data members shadowed by parameters

In Java you can access variables in a class by using the keyword this, so you don't have to figure out a new name for the parameters in a function. Java snippet: private int x; public int setX(int x) { this.x = x; } Is there something similar in C++? If not, what the best practice is for naming function parameters? ...

Is it wrong to use C++ 'using' keyword in a header file?

I've been told it's bad to have "using namespace ns123" in a header file, but I can't remember what the reason given was. Is it in fact a bad thing to do, and why? ...

Win32: BitTest, BitTestAndComplement, ... <- How to disable this junk?

WinNT.h has the following lines in it, in the VS2008 SP1 install: #define BitTest _bittest #define BitTestAndComplement _bittestandcomplement #define BitTestAndSet _bittestandset #define BitTestAndReset _bittestandreset #define InterlockedBitTestAndSet _interlockedbittestandset #define InterlockedBitTestAndReset _interlockedbittestandre...

#if 0 as a define

I need a way to define a FLAGS_IF macro (or equivalent) such that FLAGS_IF(expression) <block_of_code> FLAGS_ENDIF when compiling in debug (e.g. with a specific compiler switch) compiles to if (MyFunction(expression)) { <block_of_code> } whereas in release does not result in any instruction, just as it was like this #if 0 ...

Two classes and inline functions

I have two classes and both of them uses some of the other class, on example: // class1.h class Class1; #include "class2.h" class Class1 { public: static Class2 *C2; ... }; // class2.h class Class2; #include "class1.h" class Class2 { public: static Class1 *C1; ... }; And when I define it like in example above, it works ...

record mouse movements, clicks and keyboard input with Java or C++

I want to be able to record mouse movements, clicks and keyboard input from a user. It would be great if it was a cross platform solution. I'd like to get back something like this (pseudo code): mouse moved to 500, 500 mouse double clicked mouse moved to 800, 300 mouse left clicked keyboard typed "Hello World" Does either C++ or Jav...

Most efficient way to find the greatest of three ints

(pseudo code) function highest(i, j, k) { if(i > j && i > k) { return i; } else if (j > k) { return j; } else { return k; } } I think that works, but is that the most efficient way? ...

Are redundant include guards necessary?

Are 'redundant include guards' necessary in Codegear RAD Studio 2009? Is the compiler smart enough to deal with this on it's own? For example, I might have the following 'include guard' in foo.h: #ifndef fooH #define fooH // ... declaration here #endif and the following 'redundant include guard' in use_foo.h: #ifndef fooH #inclu...