c++

Float compile-time calculation not happening?

A little test program: #include <iostream> const float TEST_FLOAT = 1/60; const float TEST_A = 1; const float TEST_B = 60; const float TEST_C = TEST_A / TEST_B; int main() { std::cout << TEST_FLOAT << std::endl; std::cout << TEST_C << std::endl; std::cin.ignore(); return 0; } Result : 0 0.0166667 Tested on Visual Studio 2...

What's a good way to write XML in C++?

There are plenty of Libraries to parse XML, but it seems there aren't many good (?) ways to write XML in C++. Libraries I've been using so far: PugiXML: really lightweight, very straightforwarded API, but it seems to lack a way to write XML (Or I haven't found it yet) RapidXML: I don't have much experience with RapidXML; But it does l...

C++ - Implementing my own stream

Hello! My problem can be described the following way: I have some data which actually is an array and could be represented as char* data with some size I also have some legacy code (function) that takes some abstract std::istream object as a param and uses that stream to retrieve data to operate. So, my question is the following - wha...

Python C API from C++ app - know when to lock

Hi Everyone, I am trying to write a C++ class that calls Python methods of a class that does some I/O operations (file, stdout) at once. The problem I have ran into is that my class is called from different threads: sometimes main thread, sometimes different others. Obviously I tried to apply the approach for Python calls in multi-threa...

C++ compiler maximum number of classes

hello. In meta-programming number of classes grows quite fast. Is maximum number of classes modern compiler allows, for example g++, something to be concerned about? Thank you ...

converting a timestring to a duration

Hi, At the moment I am trying to read in a timestring formatted and create a duration from that. I am currently trying to use the boost date_time time_duration class to read and store the value. boost date_time provides a method time_duration duration_from_string(std::string) that allows a time_duration to be created from a time strin...

How to have 2 counters in for loop C++

Possible Duplicate: How to put 2 increment statements in c++ for loop? How do I declare 2 counters in a for loop in c++ ...

Reading Unicode files line by line C++

What is the correct way to read Unicode files line by line in C++? I am trying to read a file saved as Unicode (LE) by Windows Notepad. Suppose the file contains simply the characters A and B on separate lines. In reading the file byte by byte, I see the following byte sequence (hex) : FE FF 41 00 0D 00 0A 00 42 00 0D 00 0A 00 So ...

C++: how to publicly inherit from a base class but make some of public methods from the base class private in the derived class?

For example, class Base has two public methods: foo() and bar(). Class Derived is inherited from class Base. In class Derived, I want to make foo() public but bar() private. Is the following code the correct and natural way to do this? class Base { public: void foo(); void bar(); }; class Derived : public Base { private: void bar();...

Overloading stream insertion without violating information hiding?

I'm using yaml-cpp for a project. I want to overload the << and >> operators for some classes, but I'm having an issue grappling with how to "properly" do this. Take the Note class, for example. It's fairly boring: class Note { public: // constructors Note( void ); ~Note( void ); // public accessor methods void ...

how to omit extra bits in a file?

I want to omit extra bit in txt file.eg ....ÿ 0111111110111101100011011010010001 in this string we want to omit extra bit ÿ which is appeared when we save a binary string. Save fun is as follow. please help me. void LFSR_ECDlg::Onsave() { this->UpdateData(); CFile bitstream; char strFilter[] = { "Stream Records (*.mpl)|...

Configuring gcc compiler switches in Qt / QtCreator / QMake

I recently tried to use Qt Creator 1.3.2 / Qt 4.6.2 / gcc 4.4.0 (32-bit version) on Windows 7 (64-bit) to compile an application using some of the experimental C++0x extensions and encountered the following (fatal) error: This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently ...

How can I modify the application file of an application that is currently running (on Linux)?

I have an application running called AppFS. This application has an ext2 filesystem just attached to the end of the file (it's positioned so that the application binary exists in a 1MB spacing area, followed by the ext2 data). Now I've got FUSE embedded in the program and I've managed to extract the filesystem out of the application da...

Any high-level languages that can use c libraries?

I know this question could be in vain, but it's just out of curiosity, and I'm still much a newb^^ Anyways I've been loving python for some time while learning it. My problem is obviously speed issues. I'd like to get into indie game creation, and for the short future, 2d and pygame will work. But I'd eventually like to branch into the ...

What is the difference between bit shifting and arithmetical operations?

int aNumber; aNumber = aValue / 2; aNumber = aValue >> 1; aNumber = aValue * 2; aNumber = aValue << 1; aNumber = aValue / 4; aNumber = aValue >> 2; aNumber = aValue * 8; aNumber = aValue << 3; // etc. Whats is the "best" way to do operations? When is better to use bit shifting? ...

I don't understand how work call_once

Please help me to understand how call_once works. Here is the thread-safe code. I don't understand why this needs Thread Local Storage and global_epoch variables. The variable _fast_pthread_once_per_thread_epoch can be set to one of { FAST_PTHREAD_ONCE_INIT, BEING_INITIALIZED, FINISH_INITIALIZED }. Why are count calls needed in global_e...

C++ How to deep copy a struct with unknown datatype?

hi, i have a "data provider" which stores its output in a struct of a certain type, for instance struct DATA_TYPE1{ std::string data_string; }; then this struct has to be casted into a general datatype, i thought about void * or char *, because the "intermediate" object that copies and stores it in its binary tree should be able to...

Copy constructor demo (crashing... case 2)

Please have a glance at this program: class CopyCon { public: char *name; CopyCon() { name = new char[20]; name = "Hai";//_tcscpy(name,"Hai"); } CopyCon(const CopyCon &objCopyCon) { name = new char[_tcslen(objCopyCon.name)+1]; _tcscpy(name,objCopyCon.name); } ~CopyCon() { if( name != NULL ) { ...

Problem with receiving data form serial port in c#?

hello i have problem with receiving data from serial port in c# in am inserting a new line operator at the end of data buffer. then i send this data buffer on serial port, after this my c# GUI receiver will take this data via Readline() function but it always give me raw data not the actual one how to resolve this problem. //configuring...

Decorator pattern in C++

Can someone give me an example of Decorator pattern in C++ ? I have come across the Java version of it. But C++ i have found it difficult to understand the examples that are given. ...