c++

Run Linux commands from Daemon

Hi, I need to run a linux command such as "df" from my linux daemon to know free space,used space, total size of the parition and other info. I have options like calling system,exec,popen etc.. But as this each command spawn a new process , is this not possible to run the commands in the same process from which it is invoked? And at...

How to get the last but not empty line in a txt file.

Hi guys I want to get the last but not empty line in a txt file. This is my code: string line1, line2; ifstream myfile(argv[1]); if(myfile.is_open()) { while( !myfile.eof() ) { getline(myfile, line1); if( line1 != "" || line1 != "\t" || line1 != "\n" || !line1.empty() ) line2 = line1; } myfi...

How to call matrix palette API

I want to use matrix palette API(Like OpenGLES1.1 extension API GL_OES_matrix_palette) on mac(XCode), linux(CDT) and windows(VC++). But, those API was not able to be found. And I do not want to use shader. (Only fixed functions) ...

Pass boost::signal as boost::function

I have a class with signal member encapsulated with boost::function. Is it possible to add another signal as a handler with this API? class Foo { public: VOID AddHandler(boost::function<VOID()> handler) { m_signal.connect(handler); } private: boost::signal<VOID()> m_signal; }; boost::signal<VOID()> signal; VOID SignalC...

Examples of creating a simple COM component using C++ in Visual Studio 2008

Hello, Does anyone know of any recent examples of how to create a simple COM component in C++ using Visual Studio 2008 so I can learn how to marshal different kinds of data between unmanaged and managed code, and back again. I've found a few tutorials that suggest a C++ ATL project, but project settings page no longer has the settings m...

Is implementation-defined behavior required to be consistent between runs in C++?

Is a standard-conforming C++ implementation allowed to implement some behavior that is said to be implementation-defined in the standard in such way that it is different between different runs of the same compiled once program with the same input data? For example, is an implementation allowed to say "the behavior is this on weekends an...

What does rg mean in a member variable named m_rgNames?

I found the member variable name of m_rgNames in some source code. According to the naming convention, such as m_iNumber typed as int, rg could represent a type name. If this is case, what type did rg represent? Or else what's the meaning of rg in this variable name? ...

It is possible to determine with what gcc vesion a library(.so) has been compiled?

Hello everyone, I have a 3rd party library : lib3rdPartylib.so.It is possible to check with what version of gcc has been this library compiled? Thank you. ...

Function srand in C++

This code #include <stdio.h> #include <stdlib.h> #include <time.h> int main () { printf ("First number: %d\n", rand() % 100); srand ( time(NULL) ); printf ("Random number: %d\n", rand() % 100); srand ( 1 ); printf ("Again the first number: %d\n", rand() %100); return 0; } has the following output: First numb...

Customize Window Assert - disable button "retry"

Hello everyone, I'm using asserts in my C++ code. As you all know, when the assert condition is false, it pops up a window about the error with three buttons: abort, retry and ignore. I would like to have a solution of this two possibilities: - I would like to disable or delete the button "retry" from the windows that pops up - I would ...

How to convert 24-bit wav to mp3 with Lame using C++

Hello all, I am using the Lame library in a C++ application to encode wav files to mp3 files. It works ok for 16-bit wavs, but now I need to convert some 24-bit wavs and I cannot seem to find the way. In particular, I cannot find a function for setting the "bitwidth" parameter taken as a switch by the lame command line. (The command l...

calling methods in cpp like @selector(someMethod:) in Objective-C

In Objective-C you can pass a method A as a parameter of other method B. and call method A from inside method B very easily like this: -(void) setTarget:(id)object action:(SEL)selectorA { if[object respondsToSelector:selectorA]{ [object performSelector:selectorA withObject:nil afterDelay:0.0]; } } Is there any functiona...

C++ - Memory issues with two dimensional array

Hi guys, Following this nice example I found, I was trying to create a function that dynamically generates a 2D grid (two dimensional array) of int values in C++. It works fairly well the first couple of times you change the values but if crashes after that. I guess the part where memory is freed doesn't work as it should. Any ideas w...

For C++ Language references..which sites are beneficial ?

For C++ Language references..which sites are beneficial ? I know the basics..Up to now I am having the bookish knowledge? Please suggest me some sites. Not the tutorials.? ...

Three-way conditional in c++ to determine sign equivalance of two numbers

I need the most efficient way (in cpu cycles) to determine if two numbers have the same/different sign. But the catch is if either number is zero I need to be able to distinguish it from numbers with same/different signs (ie. zero is treated as a "third" sign). The following code is similar to what I need, but the return values can be an...

C++: float value reused across iteration

Hi guys, Let's look at the following piece of code which I unintentionally wrote: void test (){ for (int i = 1; i <=5; ++i){ float newNum; newNum +=i; cout << newNum << " "; } } Now, this is what I happened in my head: I have always been thinking that float newNum would create a new variable newNum with a brand-new val...

Template friend and nested classes

Hello, please consider the following code: template <typename T> struct foo { template <typename S> struct bar { template <typename> friend struct bar; }; }; I'd like all instantiations of foo<T>::bar to be friends of foo<T>::bar<S> for any S. If bar is not a nested template, the syntax above works just fine. B...

How to resume appending data to a file at a specific position? (std::ostream, streampos, tellp/seekp)

I'm trying to append some data to a file, but in some cases want to skip back a bit from the end to overwrite the tail end of the file. However, neither seekp( pos ) nor seekp( offset, relative ) is having any effect for me (except complaining when using a negative offset). Am I using them incorrectly or are they broken? A little exampl...

Unresolved external symbol.

Guys in this Main article there is a header file and a source file. After copying those two files and adding few headers: #include <Windows.h> #include <d2d1.h> #pragma comment(lib, "d2d1") #include <dwrite.h> #include <d2d1helper.h> #include "SafeRelease.h" //Safe realease file template<class Interface> inline void SafeRelease( ...

warning: "IPPROTO_TCP" redefined warning: this is the location of the previous definition

I am getting this warning when compiling In file included from server.c:48: unixwin.h:23:1: warning: "IPPROTO_TCP" redefined In file included from server.c:42: /usr/include/netinet/in.h:45:1: warning: this is the location of the previous definition below is the sections refered to in the error: file unixwin.h 15 16 #i...