I've noticed that whenever I write a program that uses std::cin that if I want the user to press Enter to end the program, I have to write std::cin.ignore() twice to obtain the desired behavior. For example:
#include <iostream>
int main(void)
{
int val = 0;
std::cout << "Enter an integer: ";
std::cin >> val;
std::cout...
Ok, this is an odd one: (This is EXTREMELY cut down example code. Please don't get uppity about the lack of destructors or whatever)
template <class f, class g> class Ptr;
class RealBase
{
};
template <class a, class b, class c = Ptr<a,b> >
class Base : public RealBase
{
public:
Base(){};
};
template <class d, class e>
class Deri...
I have written a library that exposes references to several related object types. All of these objects have their lifetimes managed by the library internally via boost::shared_ptr
A user of the library would also be able to know, by nature of the library, the lifetimes of any of the exposed objects. So they could store pointers or kee...
Consider following two examples.
class ClassOne
{
//class definition is here
};
std::vector< ClassOne > myListOfObjects;
std::vector< ClassOne >::const_iterator iter = myListOfObjects.begin();
Example 1:
for( ; iter < myListOfObjects.end(); **++iter**)
{
//some operations
}
OR
Example 2:
for( ; iter < myListOfObjects.end(); *...
Is it possible to call a non-static data member in a static member function?
And is it also possible to call a non-static member function in a static member function?
How do you do it?
...
I have a project which I would like to make more use of smart pointers. Overall, I have been successful in this goal. However, I've come across one things which I'm not sure what the "best practice" is.
Basically I would like to return a "pointer" from a function, but require that the user hold it in a smart pointer. Not only that, I do...
In our build process, for each project we use Post Build events to copy our executable files into a separate deployment directory. That works just peachy, but the problem is that we run into problems with stale files after performing a Clean Solution/Clean Project. I'd like to set up a "Clean" event that deletes the copied file and Vis...
We have a Coverity bug for this line of code:
snprintf( tempStr, size, testStrings[testID], A2DtoV(testResults[testID].value),
A2DtoV(testResults[testID].min),A2DtoV(testResults[testID].max));
The error says:
non_const_printf_format_string: "format string is not a string literal,
potential security vulnerability if user controlled"
...
I'd like to have access to the $HOME environment variable in a C++ program that I'm writing. If I were writing code in C, I'd just use the getenv() function, but I was wondering if there was a better way to do it. Here's the code that I have so far:
std::string get_env_var( std::string const & key ) {
...
Guys,
[question update according to updated requirements]
I've implemented following function which should return either first not null element or throw an exception.
Also could you invent more classic and shorter name like 'max', 'min', 'pair'?
template <typename T>
T select_first_not_empty( const T& a, const T&b )
{
static T null...
What is the use of having destructor as private?
...
Possible Duplicate:
The Definitive C++ Book Guide and List
Hey
I am looking for a good book to learn C++ from, given that I already know C and Java (and some other languages besides)? The books I have found at this point either assume a good understanding of C++ or that I am a complete newbie programmer.
Thanks.
...
if I create
typedef double (MyClass::*MemFuncGetter)();
in a header file, do I need to include "MyClass.h" or would forward declaring suffice?
Header file:
#ifndef _TEST_
#define _TEST_
#include "MyClass.h" //do I need this?
//or I can just say class MyClass;
typedef double (MyClass::*MemFuncGetter)();
#endif
What are the li...
I am using a 3rd party library that has a declaration like this:
typedef struct {} __INTERNAL_DATA, *HandleType;
And I'd like to create a class that takes a HandleType in the constructor:
class Foo
{
Foo(HandleType h);
}
without including the header that defines HandleType. Normally, I'd just forward-declare such a type, but I ...
I am creating a simple C++ DLL project using Visual Studio 2008 Express Edition.
I have a few classes inside a namespace, and a few non-static functions and constructors inside it are declared with __declspec(dllexport).
All those functions are implemented.
I also have an extern "C" BOOL APIENTRY DllMain function which simply returns TR...
I'm interested in a free tool that can statically check my C++ code like Lint does.
Any hints?
...
In what situation would C be a better language to work with than C++. I guess since I'm young and wasn't brought up on C like others were, so I have no clue why people tend to still use C these days when C++ is now available? What advantages does C offer that keep people still wanting to stick to it?
...
I have a situation where I'm marching through a vector, doing things:
std::vector::iterator iter = my_list.begin();
for ( ; iter != my_list.end(); ++iter )
{
if ( iter->doStuff() ) // returns true if successful, false o/w
{
// Keep going...
}
else
{
for ( ; iter != m_list.begin(); --iter ) // ...This won't work......
I'm developing an application in which distributed components talk to one another over a network, in an asynchronous, pub/sub kind of way.
For this, I like the idea of sending XML over sockets - it's asynchronous, I don't need a server of any kind, and it can work locally or over a network. I would have to roll my own pub/sub mechanism...
I know how to draw a button in C++ but how would i make an icon on it can someone post source or give reference please? by SendMessage() or if not that way just please paste
Please need easier anwsers without so many files im new a bit
...