c++

QSqlQuery UPDATE/INSERT DateTime with server's time (eg CURRENT_TIMESTAMP)

I am using QSqlQuery to insert data into a MySQL database. Currently all I care about is getting this to work with MySQL, but ideally I'd like to keep this as platform-independent as possible. What I'm after, in the context of MySQL, is to end up with code that effectively executes something like the following query: UPDATE table SET ...

QT Creator simple application

I'm developping a very simple app on my Ubuntu using QtCreator. It's a console application and I want the user to enter its name, and then I display his name. Here is the code : #include <iostream> int main(int ArgC, char* ArgV[]) { char Name[1000]; std::cout << "Type your name : "; std::cin >> Name; std::cout << "He...

Listing C/C++ functions (Code analysis in Unix)

Whether we're maintaining unfamiliar code or checking out the implementation details of an Apache module it can help if we can quickly traverse the code and build up an overview of what we're looking at. Grep serves most of my daily needs but there are some cases where it just wont do. Here's a common example of how it can help. To find...

C++: Everytime I read in by fstream I got 1 extra character at the end

Everytime I read in by fstream I got 1 extra character at the end, How can I avoid this? EDIT: ifstream readfile(inputFile); ofstream writefile(outputFile); char c; while(!readfile.eof()){ readfile >> c; //c = shiftChar(c, RIGHT, shift); writefile << c; } readfile.close(); writefile.close(); ...

C++ string sort like a human being?

I would like to sort alphanumeric strings the way a human being would sort them. I.e., "A2" comes before "A10", and "a" certainly comes before "Z"! Is there any way to do with without writing a mini-parser? Ideally it would also put "A1B1" before "A1B10". I see the question "Natural (human alpha-numeric) sort in Microsoft SQL 2005" with ...

Is a return statement mandatory for C++ functions that do not return void?

My Herb Schildt book on C++ says: "... In C++, if a function is declared as returning a value, it must return a value." However, if I write a function with a non-void return type and do not return anything, the compiler issues a warning instead of an error: "Control reaches end of non-void function." I use gcc (MinGW) and have set the -...

Build Specific .cpps

Can someone please point out where in the Visual Studio 2008 configurations I can set which .cpp files are used for a given build. I'd like to use a different set(s) of .cpp files when I am doing a release vs.debug build. Thanks! ...

Boost BGL thread safety

Hi! I'd like multiple threads to use the dijkstra_shortest_paths and astar_search functions of the BGL, and then read the property maps of the result vertices and edges. I'm wondering wether I should use mutexes to ensure thread-safety. So here are my questions: 1., Are the dijkstra_shortest_paths and astar_search functions of the Bo...

Does a const reference prolong the life of a temporary?

Why does this: #include <string> #include <iostream> using namespace std; class Sandbox { public: Sandbox(const string& n) : member(n) {} const string& member; }; int main() { Sandbox sandbox(string("four")); cout << "The answer is: " << sandbox.member << endl; return 0; } Give output of: The answer is: Ins...

LocalAlloc and LocalRealloc usage

I have a Visual Studio 2008 C++ Windows Mobile 6 application where I'm using a FindFirst() / FindNext() style API to get a collection of items. I do not know how many items will be in the list ahead of time. So, I would like to dynamically allocate an array for these items. Normally, I would use a std::vector<>, but, for other reasons,...

Is it possible to duplicate a GDI handle?

Or in my particular case a windows region (HRGN)? Updated: The problems is the following: I've a collection of objects, each of these objects can hold a HRGN. These region once acquired is released when the object is destroyed. Since some of those objects are stored in a std::vector I've to define an assignement operator. Until now I...

C++ fstream variable

Hi, please, what contains the fstream variable? A can find many tutorials on fstream, but no ona actually says what is the fstream file; declaration in the beginning. Thanks. ...

Boost timed_wait leap seconds problem

Hi, I am using the timed_wait from boost C++ library and I am getting a problem with leap seconds. Here is a quick test: #include <boost/thread.hpp> #include <stdio.h> #include <boost/date_time/posix_time/posix_time.hpp> int main(){ // Determine the absolute time for this timer. boost::system_time tAbsoluteTime = boost...

What are the lengths/limits C preprocessor as a language creation tool? Where can I learn more about these?

In his FAQ @ http://www2.research.att.com/~bs/bs_faq.html#bootstrapping, Bjarne Stroustrup says: To build [Cfront, the first C++ compiler], I first used C to write a "C with Classes"-to-C preprocessor. "C with Classes" was a C dialect that became the immediate ancestor to C++... I then wrote the first version of Cfront i...

How does the compiler know to call function once per static variable?

E.g foo1() { static const char* str = foo2(); } const char * foo2 () { ... } How does the compiler makes sure it calls foo2 just once. ...

Set volume using SDK functions causes one channel to be inactive.

Here is my problem: I made a simple mixer class for my own purposes, here it goes: struct Volume { DWORD left; DWORD right; }; CMixer::CMixer () { m_hMixer = 0; m_value = 0; } CMixer::~CMixer(void) { delete [] m_value; if (m_hMixer) mixerClose (m_hMixer); } bool CMixer::Init( UINT type /*= MAIN*/) { // ge...

c++ classes & lua

I want to have C++ objects that I can read/write in both C++ & Lua. I have looked at: http://www.lua.org/pil/28.html However, I do not like that solution, since my objects have constructors & destructors (and they are important as I use RAII and these take care of reference counts). What I don't like in the PIL solution is that the ob...

Need generated UML diagrams for C++ plugin modules

I need various UML diagrams (sequence/collaboration, class, package, and system component) from some C++ files. However, these files are plugins in a larger programming framework. I have tried generating UML from Rational Rose 7 (2002 version), but I am not very experienced and I am unsure if RR simply cannot produce the diagram, I am do...

best alternative to in-definition initialization of static class members? (for SVN keywords)

I'm storing expanded SVN keyword literals for .cpp files in 'static char const *const' class members and want to store the .h descriptions as similarly as possible. In short, I need to guarantee single instantiation of a static member (presumably in a .cpp file) to an auto-generated non-integer literal living in a potentially shared .h ...

The pImpl idiom and Testability

The pImpl idiom in c++ aims to hide the implementation details (=private members) of a class from the users of that class. However it also hides some of the dependencies of that class which is usually regarded bad from a testing point of view. For example if class A hides its implementation details in Class AImpl which is only accessibl...