c++

std::vector of known sequences

I'm trying to learn C++ by doing everything "the C++ way". I'm writing a program where I have all of these known values (at compile time). Here is my problem: In my constructor I want to check to see if a passed value(an int) is one of 2,4,8,16 or 32 and throw an error elsewise. I've though about: making a C style array or ints cre...

Better boost asio deadline_timer example

I'm after a better example of the boost::asio::deadline_timer The examples given will always time out and call the close method. I tried calling cancel() on a timer but that causes the function passed into async_wait to be called immediately. Whats the correct way working with timers in a async tcp client? ...

SNMP++ same user, different password

I'm using SNMP++ for a monitoring project. It seems if I set the same user on different boxes, with different passwords, SNMP++ tries to pull the one of the passwords out of the USM table to use on both servers.I was going to use the localized users, but you would have to do discovery first to get the engineId. Any ideas on how to get it...

C++ Builder - Spawn TThreads On the Fly

I'm looking for the ability to spawn a thread or function so that it returns immediately to the calling line and continue on with the program but continues with the thread work. For instance, if you call Form.ShowDialog(), it will create a modeless form that has its own UI thread. Is there a way to do this (no form) without having to ...

Programmatically adding a directory to Windows PATH environment variable

I'm writing a Win32 DLL with a function that adds a directory to the Windows PATH environment variable (to be used in an installer). Looking at the environment variables in Regedit or the Control Panel after the DLL has run shows me that my DLL has succeeded in adding the path to *HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Sess...

Display image in opengl.

I am fairly new to openGL. I have a 3d game that I have running, and it seems to go fairly well. What I would like to do is display an image straight onto the screen, and I am not sure the easiest way to do that. My only idea is to draw a rectangle right in front of the screen and use the image as the texture. It seems like there should ...

Testing for a non-null pointer, and returning null otherwise

I'm wondering whether it's considered okay to do something like this. if ( p_Pointer != NULL ) { return p_Pointer; } else { return NULL; } Without the else, whatever. The point is that if the pointer is null, NULL is going to be returned, so it would seem pointless wasting a step on this. However, it seems useful for debugging pur...

Sun Studio C++ "is not terminated with a newline" warning - how to suppress?

I have ported a fair bit of code from Win to Solaris, one of the issues I have - I am getting a heaps of warnings: Warning: Last line in file is not terminated with a newline. I like warnings - but because of the sheer amount of those I am afraid I could miss more important one. Which compiler (cc) option should I specify to silence...

whats the difference between c compiler and c++ compiler of microsoft c/c++ compiler?

I could compile the void main() as c++ source file with microsoft c/c++ compiler 14.00 (integrated with visual studio 2005).So does it means that the compiler does not conform to the c++ standard on the main function prototype? Is the microsoft c/c++ compiler only one compiler,that is,it is only one c++ compiler?Because C source file co...

calculating expression without using semicolon

Given the expression by input like 68+32 we have to evaluate without using a semicolon in our program. If it will be something inside the if or for loop? Reference : https://www.spoj.pl/problems/EXPR2/ ...

Checking for null before pointer usage

Most people use pointers like this... if ( p != NULL ) { DoWhateverWithP(); } However, if the pointer is null for whatever reason, the function won't be called. My question is, could it possibly be more beneficial to just not check for NULL? Obviously on safety critical systems this isn't an option, but your program crashing in a b...

Can I get a non-const C string back from a C++ string?

Const-correctness in C++ is still giving me headaches. In working with some old C code, I find myself needing to assign turn a C++ string object into a C string and assign it to a variable. However, the variable is a char * and c_str() returns a const char []. Is there a good way to get around this without having to roll my own function ...

C++ static library link with shared lib. Compiling would be fine?

Here is a C++ project, and its lib dependency is Hello.exe -> A.so -> B.a B.a -> A.so Hello.exe depends on B.a and A.so, and B.a depends on A.so. GCC compiler will link Hello.exe successful? And if there is a b.cc file in B.a which includes a header file a.h of A.so, and also uses some interfaces of A.so, then with rig...

defining stringstream and string inside if

is there a way to define std::string and std::stringstream inside if or main function as a parameter example main(int d,int m) { if(std::cin>>d) {} if(std::stringstream ss,std::string s) {} } it is giving the error expected primary-expression before ‘ss’ error: expected `)' before ‘ss’ ...

C++ array initialization

is this form of intializing an array to all 0s char myarray[ARRAY_SIZE] = {0} supported by all compilers? , if so, is there similar syntax to other types? for example bool myBoolArray[ARRAY_SIZE] = {false} ...

Execute some operation after the thread is completed

Greetings, everyone! I have a class (say, "Switcher" ) that executes some very-very long operation and notifies its listener, that operation is complete. The operation is long, and I isolate actual switching into separate thread: class Switcher { public: // this is what other users call: void StartSwitching() { // a...

Passing information between two seperate programs

I want to pass a value of an input variable in my program lets say#1 to another program #2 and i want #2 to print the data it got to screen, both are needed to be written in c++. The this will be on Linux. ...

How to programmatically set volume in Windows, Mac and Ubuntu?

I'd like to programmatically set volume in Windows, Mac and Ubuntu using C/C++. Command line also can but C/C++ preferred. Thank you in advance! ...

OpenCV with QT on Maemo 5 (N900)

Since the presentation by Eero Bragge at theAmterdam devdays about QT / QT-Creator I've been looking for an excuse to try my hands at mobile development. Now this excuse has arrived in the form of the Nokia N900, my new phone! My other hobby is computer vision, so my first Idea's for applications to try and build lie in that direction. ...

What is the best way to take generically a container in C++ using interfaces (i.e. equivalent of taking IEnumerable as argument in C#)

Hello, I would like a C++ constructor/method to be able to take any container as argument. In C# this would be easy by using IEnumerable, is there an equivalent in C++/STL ? Anthony ...