c++

Good tutorial for stringstream manipulation in C++

I'm looking for a good tutorial on how to do string manipulation with stringstream in C++. Currently, I'm doing the following: double d = 7.234; stringstream out; out.width(8); out.precision(6); out << fixed << d; I like this link for a list of what options are available, but I learn best from examples and would like to see some more...

when should a member function be both const and volatile together?

I was reading about volatile member function and came across an affirmation that member function can be both const and volatile together. I didn't get the real use of such a thing. Can anyone please share their experience on practical usage of having member function as const and volatile together. I wrote small class to test the same: ...

When should I use the new keyword in C++?

I've been using C++ for a short while, and I've been wondering about the new keyword. Simply, should I be using it, or not? 1) With the new keyword... MyClass* myClass = new MyClass(); myClass->MyField = "Hello world!"; 2) Without the new keyword... MyClass myClass; myClass.MyField = "Hello world!"; From an implementation perspect...

Doing a run-around of existing application to make database changes, good idea?

We have an existing "legacy" app written in C++/powerbuilder running on Unix with it's own Sybase databases. For complex organizational(existing apps have to go through lot of red-tape to be modified) and code reasons(no re-factoring has been done in yrs so the code is spaghetti), so it's difficult to get modifications done to this appl...

git and C++ workflow, how to handle object and archive files?

I use git to interface with an SVN repository. I have several git branches for the different projects I work on. Now, whenever I switch from one branch to another using 'git checkout ', all the compiled executables and object files from the previous branch are still there. What I would like to see is that switching from branch A to B r...

Two's complement binary form

In a TC++ compiler, the binary representation of 5 is (00000000000000101). I know that negative numbers are stored as 2's complement, thus -5 in binary is (111111111111011). The most significant bit (sign bit) is 1 which tells that it is a negative number. So how does the compiler know that it is -5? If we interpret the binary value gi...

Howto read chunk of memory as char in c++

Hello I have a chunk of memory (allocated with malloc()) that contains bits (bit literal), I'd like to read it as an array of char, or, better, I'd like to printout the ASCII value of 8 consecutively bits of the memory. I have allocated he memory as char *, but I've not been able to take characters out in a better way than evaluating ea...

Meaning of gcc -O2

I see this flag a lot in the makefiles. What does it mean? and when should it be used? ...

Passing a smart pointer as argument inside a class: scoped_ptr or shared_ptr ?

I have a class that creates an object inside one public method. The object is private and not visible to the users of the class. This method then calls other private methods inside the same class and pass the created object as a parameter: class Foo { ... }; class A { private: typedef scoped_ptr<Foo> FooPtr; void pri...

How to program a RPG game in C++ with SDL?

I want to know how to program a 2D RPG game in C++ with SDL. I searched, but I haven't found anything good. Many of the articles were too basic and didn't delve into anything practicical. Can anyone help give me some articles, free books or other resources so I can learn how to program a RPG using C++ and SDL? EDIT: I don't need do...

manipulation of fields in an array of bits in c++

So I'm wondering about both setting and manipulating bit fields. I've already found http://stackoverflow.com/questions/264552/cc-code-to-treat-a-character-array-as-a-bitstream which is similar to my question I guess but it doesn't doesn't give me a nice stl approach I am thinking has to exist. I was thinking of bitsets from the stl ...

add new member to copy c-tor/copy o-tor/serialization reminder.

Almost all c++ projects have classes with copy c-tor/copy operator/serialize method etc. Which usualy doing something with all members. But sometimes developers forgets to add new member to this functions. Do you know any easy, not wrapp all members way which will remind developers to do something or write noop(memeber_name_) in this fu...

Why do I keep getting "Must declare the Scalar variable "@Param1"" when performing a parameterized query in C++ using ADO?

Here is the code. A Few notes about it. DStr is an string class that is internal to our company. It functions much like CString. I can connect to the database and run non-parameterized queries. Also this insert works fine if I do not use parameters. The cmd->Execute statment throws an exception. This is where I am getting the error...

Modern C++ Design Generic programming and Design Patterns Applied

I have purchase this book for our group in the company, perhaps, to improve our design skills and ultimately have a better programming practices. As I read it, I find, mostly, a set of nifty tricks that can be used with template, and not sure if it is worthwhile - and not detrimental-to incorporate it into our code thus introducing c...

When should I use C++ private inheritance?

Unlike protected inheritance, C++ private inheritance found its way into mainstream C++ development. However, I still haven't found a good use for it. When do you guys use it? ...

Is there any way to get readable gcc error and warning output at the command line?

For some long errors, the gcc output is dense and has lots of line-wrapping etc. Especially when errors are subtle, it can take me 10-30 seconds of squinting to parse it with my eyes. I've taken to pasting this in an open code-editor window to get some basic syntax highlighting and enable reformatting with regex's. Has anyone invented...

Virtual inheritance in C++ usages/tricks

I've never used it in the professional software even though in our shop, and others I have worked for, we design large scale systems. The only time I messed with virtual inheritance was during my interview in a company. Nonetheless, I played with it during afterhours. Do you guys use it? Do you understand how it works in depth (how mo...

GetOpenFileName() with OFN_ALLOWMULTISELECT flag set

Hello, I'm trying to use the GetOpenFileName() common dialog box call to pop open a dialog box and allow the user to select multiple files. I've got the OFN_ALLOWMULTISELECT flag set, as well as OFN_EXPLORER set so I get the "new style" file selection box. When I set up my OPENFILENAME structure, I have ofn.lpstrFile pointing to a buff...

vim, ctags, and identically named identifiers

vim + ctags works well for C projects, since C does not allow function overloading and, in general encourages manual prefixing of symbols due to rudimentary scoping facilities. In C++, functions are frequently overloaded, and overridden in subclasses. This makes vim always jump to the tag in the wrong class on "Ctrl + ]". Is there a way...

Parsing buffer in C++ using OOP and STL

I want to use OOP and STL etc to parse a buffer. My Buffer contains ABCDXXXX333$$$$YYYY I need to separate ABCD XXXX 333 $$$$ YYY and move them to struct. I have their offset defined in one of the rule table and how many elements are in the buffer. A few of the fields are delimited also. Any suggestions what STL features I can use...