c++

How is the C++ standard library linked to my application?

When I usually use code (include headers) from 3rd party (non-standard) C++ libraries, a pre-built binary file is linked to (or included in) the target executable that represents my application, but what happens with C++ standard library?, as far as I have seen I don't have to ship a library with an application that uses code only from t...

Recursive function with static variable

I have a recursive function with a static variable "count". The function increments count recursively and since it has file scope, when I call foo() a second time, count is still equal to 5. Is there a technique to reset count to 0 before the second time foo() is called? Basically, I don't want count to have file scope but I want it to ...

How to Avoid DOS Attack using Berkeley Sockets in C++

I'm working my way through UNIX Network Programming Volume 1 by Richard Stevens and attempting to write a TCP Echo Client that uses the Telnet protocol. I'm still in the early stages and attempting to write the read and write functions. I'd like to write it to use I/O Multiplexing and the Select function, because it needs to be multi...

Random segfaults in C++

I'm new to C++ and I haven't a clue where to start, so I uploaded the code to a pastebin because there is a lot of it. This code compiles fine, and doesn't give off a warning, even with gcc's -Wall option. It's supposed to generate all prime numbers up to a number given as a command line parameter. On smaller numbers (e.g. 4,000 or 5,...

C++ : error: invalid operands of types ‘String*’ and ‘const char [7]’ to binary ‘operator+’

Hi, I'm learning cpp and In my last assignment I am rewriting the std::string class. so here is an outline of my code: string class: class String { public: String(const char* sInput) { string = const_cast<char*> (sInput); } const String operator+(const char* str) { //snip print(); ...

Returning C/C++ structure array in XML/XSD format

Hi all: I am writing a native C/C++ .dll program which calls to .dll functions of many third party C/C++ libraries and returns a c/c++ structure array (SA) of 18 columns by 0-n lines. This returned value is then captured by a WCF C# web service program which "interop" with my .dll and, using .net xml library, serialize the result before...

Checking if DWM/Aero is enabled, and having that code live in the same binary for 2000/XP/Vista/7

I know the title makes little sense, mostly because it's hard to explain in just one line. So here's the situation: I have a program who's binary is targeted at Windows 2000 and newer. Now, I went ahead and added some code to check if the user is running under Vista/7, and if so then check if Aero/DWM is enabled. Based on this I'll disa...

How to cope with extraneous characters left on the input stream? (cin skipped)

Sorry for the noobish question here, but I am just learning C++ and I am looking for the standard way of dealing with this problem. I am using VS2005. Given a program: #include <iostream> using namespace std; int main( ) { while ( true ) { cout << "enter anything but an integer and watch me loop." << endl; ...

Error seen while trying to compile live555 video streaming platform code in Visual Studio 9.0

Dear Mr. Butterworth, I am trying to compile the video streaming live 555 platform code on my system using Microsoft Visual Studio 9.0. The code is available in this link: http://www.live555.com/liveMedia/public/ I have generated the makefiles for this code using the provided genWindowsMakefiles script provided here. The problem I enco...

finished writing a poker hand evaluator looking for a new project

just finished writing a five card poker hand evaluator in C++. now im looking for a new project about the same level of difficulty. maybe a very simple DOS command parser? ...

Any built-in function to test if 4 is in [1,2,3,4] (vector)

In Ruby I can do: [1,2,3,4].include?(4) #=>True In Haskell I can do : 4 `elem` [1,2,3,4] #=> True What should I do in C++? ...

How to declate a wide char constant in an IDL

We are migrating our C++ COM application to be unicode, and as part of this migration we want to migrate the constant strings in our IDL to unicode as well. The problem is that at the moment, we still compile it both in ANSI and in UNICODE, which means that we can't use the L"String" construct to declare wide charts. At the moment, our...

template specialization of template class

Hello, I want to specialize following member function: class foo { template<typename T> T get() const; }; To other class bar that depends on templates as well. For example, I would like bar to be std::pair with some template parameters, something like that: template<> std::pair<T1,T2> foo::get() const { T1 x=...; T2...

Policy based design decisions

Hello, I have a class called Device that accepts two policies as far as I can see: StatePolicy and BehaviorPolicy. The StatePolicy holds and manages the state of the device. The BehaviorPolicy wraps the device driver that is written in C or C++. Now I have two questions: How to coordinate between the state and the behavior policies? ...

Threads using visual stdio2008

I want to implement threading in c++.I am using visual stdio2008 and wish to implement threading using pthreads.can any one guide me about pthreads and also about there implementations in vs2008.Thanking in anticipation ...

Comprehesive information on serial ports and programming?

What are some comprehesive sources on serial programming? Ideally they would cover things like: history of devices current and future uses how serial devices work protocols and, of course, how to program, preferably in C/C++ ...

Can a pointer be stored in std::mbstate_t type?

I'm writing an implementation of std::codecvt facet that uses iconv. This implementation stores a pointer to heap-allocated data in std::mbstate_t state argument. Everything works fine, but is this code 64-bit compatible? Is there a platform where a pointer size exceeds the size of std::mbstate_t? ...

Different destructor behavior between vc9 and gcc

The following code gives a different number of destructors when compiled on GCC and vc9. AFAIK when run on vc9 i get 5 destructors showing, which I understand. The + overloaded operator is called, and two object are created, when returned a temporary object is created. This makes destruction of 3 objects possible. When the overloaded = o...

Code::Blocks Problem - Can't break file format after uninstalling Visual C++ Express

I decided to try Visual C++ Express and didn't like it so I went back to Code::Blocks. However, when I went to run a program in Code::Blocks I noticed that all of my files were saved under the format VCExpress.cpp.9.0. I deleted all of the files and went to where I have all of them uploaded to re-download them. However, they keep being s...

Analysing a crash in Windows: what does the error message tell us?

A small utility of mine that I made for personal use (written in C++) crashed randomly yesterday (I've used it roughly 100+ hours with no issues so far) and while I don't normally do this, I was feeling a bit adventurous and wanted to try and learn more about the problem. I decided to go into the Event Viewer and see what Windows had log...