c++

Does the GPLv2 preclude me from using KLone for my website?

I recently discovered Klone. Being a C++ developer, I'm fascinated by the idea of getting to use C++ for my web development work (I know, I'm a glutton for punishment!)... Anyhow, it looks like the open source version of KLone is licensed under GPLv2... Normally, this would be fine, but since you're app is compiled and linked right into ...

Java to/from C++ socket communication, DataInputStream and eof, binary, encryption

I'm trying to have Java server and C++ clients communicate over TCP under the following conditions: text mode, and binary/encrypted mode. My problem is over the eof indicator for end of stream that DataInputStream's read(byte []) uses to return with -1. If I send binary data, what's to prevent a random byte sequence happening to repres...

pimpl idiom vs. bridge design pattern

I just noticed a new term pimpl idiom, what's the difference between this idiom with Bridge design pattern? I am confused about that. I also noticed the pimpl idiom is always used for swap function, what's that? Could anybody give me an example? ...

What's wrong with my code?

void GasPump::dispense() { bool cont = true; char stop; do{ cout << "Press any key, or enter to dispense.\n" << "Or press 0 to stop: \n"; cin.get(stop); gasDispensed = gasDispensed + gasDispensedPerCycle; charges = costPerGallon*gasDispensed; displayGasNCharges()...

Does the following code invoke Undefined Behavior?

#include <iostream> #include <cmath> #define max(x,y) (x)>(y)? (x): (y) int main() { int i = 10; int j = 5; int k = 0; k = max(i++,++j); std::cout << i << "\t" << j << "\t" << k << std::endl; } ...

Breaking down WinMain's cmdLine in old style main()'s arguments

I want to convert WinMain's cmdLine argument to argc and argv so I can use the argument parsing function I wrote for console applications. This would be trivial except that I want to support "quotes" too. For example: test.exe test1 test2 "testing testing" should be argv[0] = "test.exe"; argv[1] = "test1"; argv[2] = "test2"; argv[3] ...

Tracking down strange error

I'm trying to do some C++ exercises, but I'm running into a error on build, which doesn't just jump out at me. What am I missing? I'm just getting back to C++ from C# et al after having done it years ago. [ERROR] syntax error : 'return' [/ERROR] #include <iostream> using namespace std; /* Pre-compiler directives / macro...

An initial value assumption about map in c++

I am initializing a map map<string,int> ex; in C++. I could not find contains_key or similar function in stl, hence I am just using ex[inputString]++; The debugger shows the int to be initialized to zero correctly, is it a good assumption? ...

partial specialization of template class issue!

The following code is confusing me //partial specialization of vector template<class t> class vector {.... }; template<class t> //teacher said that this partial specialization will handle all type of pointers class vector<t*> ... }; This is confusing me a lot, Suppose t is a char* , as the compiler will first look for the complete sp...

How to test if a string contains any digits in C++

I want to know if a string has any digits, or if there are no digits. Is there a function that easily does this? ...

Need clarifications in C-style, reinterpret, and const casts

Am I right in assuming that C-style casts (which are discouraged) are nothing but reinterpret_casts? Using the latter is visually striking and easy to search when looking for nasty casts, and hence it's recommended over C-style casts? If casting away const using const_cast and writing to a originally const object is undefined, what is t...

How to globally mute and unmute sound in Vista and 7, and to get a mute state?

I'm using the old good Mixer API right now, but it does not work as expected on Windows Vista & 7 in the normal, not in XP compatibility mode. It mutes the sound for the current app only, but I need a global (hardware) mute. How to rearch the goal? Is there any way to code this w/o COM interfaces and strange calls, in pure C/C++? ...

sort std::list case sensitive elements

#include <list> #include <string> using std::string; using std::list; int main() { list <string> list_; list_.push_back("C"); list_.push_back("a"); list_.push_back("b"); list_.sort(); } does sort() function sort the elements according to their character codes? I want the result here to be a b C after the sorting i...

What may be the causes of the error 0x80010108 (The object invoked has disconnected from its clients)?

Hi, In C++ program the call to method of coclass returns the error 0x80010108 (The object invoked has disconnected from its clients). What may be the causes of that? ...

How to find the first character in a C++ string

I have a string which starts out with a lot of spaces. If I want to find out the position of the first character that is not a space, how would I do that? ...

Why does a class used as a value in a STL map need a default constructor in ... ?

Below is the class used as the value in a map: class Book { int m_nId; public: // Book() { } Inside main(): map for( int i = 0; i ++i ) { Book b( i ); mapBooks[ i ] = b; } The statement causing the error is: mapBooks[ i ] = b; If I add a default constructor, the error does not appear...

C++ EOF Getline Error

I was using the form used in one of the related questions. Only problem is that i keep getting right at the end of the file. The file is an fstream and the str is a string. Unhandled exception Microsoft C++ exception: std::ios_base::failure while (getline(file, str)) { } if (cin.bad()) { // IO error } else if (!cin.eof()) ...

What is segmentation fault?

What is segmentation fault? Is it different in C and C++? How are segmentation fault and dangling pointer related? ...

How do I fix class template has already been defined?

I am implementing ZipArchive library into my project, and I fought with it for over an hour getting it setup right to stop all the linker errors. But now I still have this left over and I am not sure of the best approach to fix it, could use some help. C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxtls_.h(199) : error...

warning: GDB: Failed to set controlling terminal: Operation not permitted

I get this error (title of this question), when I am attempting to debug C/C++ programs using gdb with Netbeans IDE. Does anyone know what this means, and how to get rid of the warning? I am able to debug despite the warning, but I'd still like to make the warning go away. Relevant details: OS: Ubuntu 9.10 gdb: 7.0-ubuntu Netbeans: ...