question_id int64 25 74.7M | answer_id int64 332 74.7M | title stringlengths 20 150 | question stringlengths 23 4.1k | answer stringlengths 20 4.1k |
|---|---|---|---|---|
466,568 | 466,592 | (C++) Need to figure out all points within a radius using reg. 2D windows coord. system | Sorry in advance, I'm struggling a bit with how to explain this... :)
Essentially, I've got a typical windows coordinate system (the Top, Left is 0,0). If anybody's familiar with the haversine query, like in SQL, it can get all points in a radius based on latitude and longitude coordinates.
I need something much simpl... | Use Pythagoras:
distance = sqrt(xDifference^2 + yDifference^2)
Note that '^' in this example means "to the power of" and not C's bitwise XOR operator. In other words the idea is to square both differences.
|
466,802 | 467,363 | How do I parse this correctly with spirit? | My situation: I'm new to Spirit, I have to use VC6 and am thus using Spirit 1.6.4.
I have a line that looks like this:
//The Description;DESCRIPTION;;
I want to put the text DESCRIPTION in a string if the line starts with //The Description;.
I have something that works but looks not that elegant to me:
vector<char> vD... | You might try using confix_p:
confix_p(as_lower_d["//the description;"],
(+print_p)[assign(vDescription)],
ch_p(';')
)
It should be equivalent to Fred's response.
The reason your code fails is because print_p is greedy. The +print_p parser will consume characters until it encounters the end o... |
466,820 | 466,842 | Math Resources for C/C++ Programmers | My degree is in Electrical and Computer Engineering but i'm currently employed as a Software Engineer. I took all of the algebra, geometry and calculus classes that one would expect from someone with my degree however I must admit, I think I learned just enough to pass the test but never really saw a use for it and the... | I found this blog on the subject intresting:
http://steve-yegge.blogspot.com/2006/03/math-for-programmers.html
also has some recommendations for books.
|
466,827 | 466,866 | Warnings and SunStudio C++ compiler | I talked my team into turning on compiler warnings again. Some how all warnings (-w) were disabled (don't ask...). Most of them are obvious but one of them is really annoying. I get it from my date and time classes which are used in lots of places. Story is really simple. Time is subclass of Date and both of them have ... | I can help you with that particular warning - it looks a lot like this one from C++ FAQ Lite. Did you by chance change the type of argument that ACTime::operator- uses from the one in ACDate?
|
467,139 | 467,177 | Portable wchar_t in C++ | Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it.
| If you're dealing with use internal to the program, don't worry about it; a wchar_t in class A is the same as in class B.
If you're planning to transfer data between Windows and Linux/MacOSX versions, you've got more than wchar_t to worry about, and you need to come up with means to handle all the details.
You could de... |
467,150 | 665,635 | What are some good C++ resources for effectively using Apache XML Security? | I'm looking for some resources that allow me to understand how to use this library, particularly for signing XML. Most of what I found out there is Java related, and I would prefer to get documentation/FAQs/tutorials on the C++ library.
| I had the same problem. The best information I could find was on the Apache website itself ( http://santuario.apache.org/c/programming.html ), the API docs and by looking at the code of the examples and tools (like templatesign) they provide.
This information combined with some experimenting was enough for me to sign a... |
467,300 | 474,157 | How to use msxml with Visual Studio 2008 Express (no ATL classes) without becoming crazy? | It is not really a question because I have already found a solution. It took me a lot of time, that's why I want to explain it here.
Msxml is based on COM so it is not really easy to use in C++ even when you have helpful classes to deal with memory allocation issues. But writing a new XML parser would be much more diff... | I'm happy I posted my question although I already had a solution because I got several alternative solutions. Thanks for all your answers.
Using another parser such as eXpat or the maybe smaller (not so powerfull but enough for my needs) TinyXML could actually be a good idea (and make it easier to port the program to a... |
467,327 | 467,376 | Upgrading to SQL Server 2005: Cannot INSERT QNAN into float column? | Background:
I'm working on migrating from SQL Server 2000 to SQL Server 2005. This is providing DB service for a C++ application that uses SQL Native Client to communicate with SQL Server via ODBC.
Problem:
I'm attempting to insert QNAN into a float column in the database. In my application, this value is stored as a... | According to the response to this bug report, SQL Server 2005 does not accept NaN or infinity, and this was apparently by design (due to sorting/comparison issues).
|
467,640 | 467,695 | Compiler Error when adding dll reference to managed c++ project | I am using VS 2008 and get compiler errors sporadically when adding a dll reference to a managed c++ file in my C++ project. I am trying to add a reference to the dll so as to be able to use smart pointers.
ex: #import items.tlb
The problem is that the compiler crashes at sporadic places inside of items.tlh almost as ... | Whenever I've had this problem, it was caused by linking a Debug build to a Release DLL or a Release build to a Debug DLL.
|
467,762 | 467,804 | Which language/platform to develop desktop application based on following criteria | Faced with the challenge of a new application with which you had free reign to design, assemble a team to develop and manage:
Which language/platform would you choose?
Why?
Background: The desktop application will control a hardware device and perform computations, analyze and display the data returned by it.
Requir... | To be honest, I'd choose Java (with a small component of C) for the following reasons, based on your requirements.
Lifetime of language/API/platform/framework- i.e., how future-proof will the investment in this application be?... the product has a long life-cycle (10). That really depends on what you mean by long. I s... |
467,815 | 467,830 | Class method and variable with same name, compile error in C++ not in Java? | class Test {
bool isVal() const {
return isVal;
}
private:
bool isVal;
};
On Compiling this file it says
testClass.cpp:9: declaration of `bool
Test::isVal'
testClass.cpp:3: conflicts with
previous declaration `bool
Test::isVal()'
Although the same would work for java
class Te... | Because C++ is not Java. You can take the address of a member:
&Test::isVal
So you can't have two members have the same name, except that you can overload member functions. Even if you could disambiguate that by some kind of cast, the next problem would already arise at other places.
In C++, a lot of people including... |
467,851 | 467,853 | Why can't we use "this" inside the class? | E,g
class Test {
public:
void setVal(const std::string& str) {
this.isVal = str; //This will error out
}
private:
string isVal;
};
| In C++, this is a pointer (as opposed to a reference). So you have to say this->isVal instead.
|
468,090 | 468,430 | How to restructure this code hierarchy (relating to the Law of Demeter) | I've got a game engine where I'm splitting off the physics simulation from the game object functionality. So I've got a pure virtual class for a physical body
class Body
from which I'll be deriving various implementations of a physics simulation. My game object class then looks like
class GameObject {
public:
// .... | The idea of the law of Demeter is that your GameObject isn't supposed to have functions like GetPosition(). Instead it's supposed to have MoveForward(int) or TurnLeft() functions that may call GetPosition() (along with other functions) internally. Essentially they translate one interface into another.
If your logic r... |
468,134 | 468,214 | Newbie question about manual memory management and deep copying | Alright, so I'm trying out C++ for the first time, as it looks like I'll have to use it for an upcoming course in college. I have a couple years of programming under my belt, but not much in the non-garbage-collected world.
I have a class, a Node for use in a doubly linked list. So basically it has a value and two poin... | First of all, I'm not really sure how the objective of the exercise should be understood. How deep should the copy be? In a solution like yours, this->next->next and other.next->next would be still the same thing. Should this object also be duplicated? And the rest of the list? Where does it end? One could of course de... |
468,311 | 468,396 | Using the "Very Sleepy" profiler to profile DLLs | I have a DLL that I want to profile.. I tried to use Very Sleepy, but I can't seem to get the source file column to display which source file the functions came from, all it displays is "unknown".. Anyway, I'm really baffled on how to use this app.. Can anyone point me to some help? There's not much documentation on i... | You're going to need debugging information (PDB files) if you want to know the source file and column. That information doesn't get saved unless you ask for it.
Unfortunately the profiler has no documentation that I can find. However, there are definitions for inclusive and exclusive when it comes to profiling:
inc... |
468,388 | 468,392 | "Inherit not, contain" or "inherit, not contain" | I have an application which spawns a lot of child objects and each of them works with some global application objects e.g. registers itself in the global application registry, updates application statistics etc.
How should application transfer the ability to access those global objects to the children? Should every chi... | It would seem very odd to inherit from CRegistry - the child objects aren't just specialized registries, are they? Their interaction with the registry is just to register themselves and then be found within the registry, I'd imagine. Ditto statistics.
It certainly sounds to me like the registry and statistics should ju... |
468,486 | 468,558 | Warning C4099: type name first seen using 'class' now seen using 'struct' (MS VS 2k8) | Is this warning anything to worry about? I've read that it can cause erratic behaviour?
It's an example I'm trying to compile, could someone explain to me why the author declares the object as a class but then typedef's it to a structure? Is it perfectly normal to do so if the class is POD?
Thanks.
| This warning appears when you have a one type declaration that contradicts another (one says "class", the other says "struct"). Given the one definition rule, all declarations except for at most one must be forward declarations. The warning will generally indicate that a forward declaration of a type is wrong and is ... |
468,956 | 468,981 | How to get C++ object name in run time? | Can I get an object's name in run time (like getting an object's type via RTTI)? I want the object to be able to print its name.
| Its not possible. For on thing, an object doesn't have a unique name.
A a;
A& ar = a; // both a and ar refer to the same object
new A; // the object created doesn't have a name
A* ap = new A[100]; // either all 100 objects share the same name, or need to
// know that they are part of an arra... |
469,152 | 471,306 | Using ShellExecuteEx and capturing standard in/out/err | I'm using ShellExecuteEx to execute a command in C. Is there a way to use ShellExecuteEx and capture standard in/out/err?
Note: I don't want to use CreateProcess.
| As mentioned by pilif and Bob, you need to use CreateProcess.
If you want code that wraps it all up for you, I do have a class for this exact issue at:
http://code.google.com/p/kgui/source/browse/trunk/kguithread.cpp.
The class (kGUICallThread) handles Linux, macOS and Windows versions. The code is licensed LGPL.
|
469,401 | 469,836 | Lazy object creation in C++, or how to do zero-cost validation | I've stumbled across this great post about validating parameters in C#, and now I wonder how to implement something similar in C++. The main thing I like about this stuff is that is does not cost anything until the first validation fails, as the Begin() function returns null, and the other functions check for this.
Obv... | Other than the fact that C++ does not have extension methods (which prevents being able to add in new validations as easily) it should be too hard.
class Validation
{
vector<string> *errors;
void AddError(const string &error)
{
if (errors == NULL) errors = new vector<string>();
errors->push_ba... |
469,477 | 472,350 | Find nearest points in a vector | Given a sorted vector with a number of values, as in the following example:
std::vector<double> f;
f.pushback(10);
f.pushback(100);
f.pushback(1000);
f.pushback(10000);
I'm looking for the most elegant way to retrieve for any double d the two values that are immediately adjacent to it. For example, given the value "45... | I'm going to post my own anser, and vote anyone up that helped me to reach it, since this is what I'll use in the end, and you've all helped me reach this conclusion. Comments are welcome.
std::pair<value_type, value_type> GetDivisions(const value_type& from) const
{
if (m_divisions.empty())
throw 0; // Can... |
469,508 | 500,389 | Visual Studio Compiler warning C4250 ('class1' : inherits 'class2::member' via dominance) | The following code generates warning C4250. My question is, what's the best solution to it?
class A
{
virtual void func1();
}
class B : public A
{
}
class C : public A
{
virtual void func1();
}
class D : public B, public C
{
}
int main()
{
D d;
d.func1(); // Causes warning
}
According to what I've read it ... | I had the same warning for the following code:
class Interface
{
public:
virtual void A() = 0;
};
class Implementation : public virtual Interface
{
public:
virtual void A() {};
};
class ExtendedInterface : public virtual Interface
{
virtual void B() = 0;
};
class ExtendedImplementation : public ExtendedI... |
469,597 | 469,613 | Destruction order of static objects in C++ | Can I control the order static objects are being destructed?
Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static object?
| The static objects are destructed in the reverse order of construction. And the order of construction is very hard to control. The only thing you can be sure of is that two objects defined in the same compilation unit will be constructed in the order of definition. Anything else is more or less random.
|
469,722 | 469,841 | What advantage does C++ have over .NET when it comes to to game development and apps like VirtualBox | This is an attempt to rephrase a question I asked earlier. I'd like to know why C++ seems to be the language of choice for certain thick client apps. The easiest example I can think of is video games and my favorite app VirtualBox.
Please don't close this post I'm just trying to understand why this is the case.
| As a profesional game dev working on AAA titles I can tell you. Reason number 1 is C++ and C will compile and run on any platform say a PS3 or an NDS. Next platform makers only provide robust C libraries to interface with hardware. The reason behind this is C and C++ are free, and not owned by one corporation, and beca... |
469,751 | 470,200 | Winform Not Displaying in Designer | I have a Managed C++ WinForm that suddenly stopped showing in the VS 2005 designer. The error it shows is
Could not find type 'int'. Please
make sure that the assembly that
contains this type is referenced. If
this type is a part of your
development project, make sure that
the project has been successfully
... | This is troubleshooting for C# but I'd assume a couple of the points mentioned here would help.
What's the state of play with "Visual Inheritance"
|
469,849 | 469,861 | Using an STL Iterator without initialising it | I would like to do something like this:
container::iterator it = NULL;
switch ( eSomeEnum )
{
case Container1:
it = vecContainer1.begin();
break;
case Container2:
it = vecContainer2.begin();
break;
...
}
for( ; it != itEnd ; ++it )
{
..
}
But I can't create and initialise an iterator to NULL. Is there some way I... | You just needn't initialize it at all, because iterators are DefaultConstructible.
|
469,892 | 470,451 | C++ Why is this passed-by-reference array generating a runtime error? | void pushSynonyms (string synline, char matrizSinonimos [1024][1024]){
stringstream synstream(synline);
vector<int> synsAux;
int num;
while (synstream >> num) {synsAux.push_back(num);}
int index=0;
while (index<(synsAux.size()-1)){
... | What's wrong with it
The code as you have it there - i can't find a bug. The only problem i spot is that if you provide no number at all, then this part will cause harm:
(synsAux.size()-1)
It will subtract one from 0u . That will wrap around, because size() returns an unsigned integer type. You will end up with a very... |
470,040 | 470,053 | boost::bind with functions that have parameters that are references | I noticed that when passing reference parameters to boost bind, those parameters won't act like references. Instead boost creates another copy of the member and the original passed in variable remains unchanged.
When I change the references to pointers, everything works ok.
My question is:
Is it possible to get refer... | The boost documentation for bind suggests that you can use boost::ref and boost::cref for this.
|
470,388 | 470,411 | My C++ object file is too big | I am working on a C++ program and the compiled object code from a single 1200-line file (which initializes a rather complex state machine) comes out to nearly a megabyte. What could be making the file so large? Is there a way I can find what takes space inside the object file?
| There can be several reasons when object files are bigger than they have to be at minimum:
statically including dependent libraries
building with debug information
building with profiling information
creating (extremely) complex data structures using templates (maybe recursive boost-structures)
not turning on optimizi... |
470,544 | 470,563 | Compilation error when calling _tcsstr and assigning to a wchar_t* | I am getting a compilation error when trying to build a C++ project which previously worked.
The code follows:
const wchar_t* pdest;
pdest = _tcsstr(ConnStr, Name);
The error follows:
Error 10 error C2440: '=' : cannot convert from 'const char *' to 'const wchar_t
I'm using Visual Studio 2008. The error message e... | Your code is dangerous. _tcsstr is a TCHAR macro, so it's definition can change depending on whether or not UNICODE is defined. wchar_t is fixed. The error you're seeing is due to this exact problem - the environment is using the single-byte version of _tcsstr (likely becasue UNICODE is not defined).
Don't just defi... |
470,835 | 476,403 | A C++ iterator adapter which wraps and hides an inner iterator and converts the iterated type | Having toyed with this I suspect it isn't remotely possible, but I thought I'd ask the experts. I have the following C++ code:
class IInterface
{
virtual void SomeMethod() = 0;
};
class Object
{
IInterface* GetInterface() { ... }
};
class Container
{
private:
struct Item
{
Object* pObject;
... | I've now found a solution which is fitter for my original purpose. I still don't like it though :)
The solution involves MagicIterator being templated on IInterface* and being constructed with both a void* to an iterator, the byte size of said iterator, and a table of pointers to functions which perform standard iterat... |
470,840 | 471,182 | How do I resolve LNK1104 error with Boost Filesystem Library in MSCV? | I am having trouble getting my project to link to the Boost (version 1.37.0) Filesystem lib file in Microsoft Visual C++ 2008 Express Edition. The Filesystem library is not a header-only library. I have been following the Getting Started on Windows guide posted on the official boost web page. Here are the steps I ha... | Ferruccio's answer contains most of the insight. However, Pukku made me realize my mistake. I am posting my own answer to give a full explanation. As Ferruccio explained, Filesystem relies on two libraries. For me, these are:
libboost_system-vc90-mt-gd-1_37.lib
libboost_filesystem-vc90-mt-gd-1_37.lib
I must not h... |
471,198 | 471,389 | Is there any good example of http upload using WinInet c++ library | I cannot get my code to work :/
| Here's a quick example from Microsoft.
static TCHAR hdrs[] =
_T("Content-Type: application/x-www-form-urlencoded");
static TCHAR frmdata[] =
_T("name=John+Doe&userid=hithere&other=P%26Q");
static LPSTR accept[2]={"*/*", NULL};
// for clarity, error-checking has been removed
HINTERNET hSession... |
471,228 | 471,243 | error: conversion from long int to non-scalar type, comparing an iterator to null | Hello I hope someone can explain this problem. This is the code:
class Memory{
public:
PacketPtr pkt;
MemoryPort* port;
MemCtrlQueueEntry(){};
};
And after I do:
std::list<Memory*>::iterator lastIter = NULL;
And I get the following error:
error: conversion from long int to non-scalar type std::_List_itera... | Iterators are not pointers. If you want to initialize them to a non-value, use list::end(). The fact that vector<T>::iterator is sometime implemented with a pointer is an implementation detail that you cannot depend on.
If you want to assign NULL to the value at the location that the iterator is refering to, you have... |
471,265 | 473,105 | Importing png Files in Visual studio C++ Resource Editor | I would like to be able to import png file inside of Visual Studio Resource Editor so as to be able to use the embedded resource in different other projects . Is there a solution for that? I know that it works for bitmaps but i am interested in the pngs because of the "transparency" that is availble even on lower forma... | With VS 2008 you can import pngs and they will be recognized as an image, ie you will able to "see" it, but you will not be able to modify with within the resource editor.
But anyway the problem is that they will no be treated as bitmaps, so you can't embedded it inside a dialog. But you can access it with the usual Fi... |
471,344 | 471,718 | Guaranteed file deletion upon program termination (C/C++) | Win32's CreateFile has FILE_FLAG_DELETE_ON_CLOSE, but I'm on Linux.
I want to open a temporary file which will always be deleted upon program termination. I could understand that in the case of a program crash it may not be practical to guarantee this, but in any other case I'd like it to work.
I know about RAII. I k... | The requirement that the name remains visible while the process is running makes this hard to achieve. Can you revisit that requirement?
If not, then there probably isn't a perfect solution. I would consider combining a signal handling strategy with what Kamil Kisiel suggests. You could keep track of the signal hand... |
471,432 | 471,461 | In which scenario do I use a particular STL container? | I've been reading up on STL containers in my book on C++, specifically the section on the STL and its containers. Now I do understand each and every one of them have their own specific properties, and I'm close to memorizing all of them... But what I do not yet grasp is in which scenario each of them is used.
What is t... | This cheat sheet provides a pretty good summary of the different containers.
See the flowchart at the bottom as a guide on which to use in different usage scenarios:
Created by David Moore and licensed CC BY-SA 3.0
|
471,438 | 822,520 | shared_ptr in std::tr1 | I am working on a platform with a gcc compiler however boost cannot compile on it.
I am wondering what is the proper way to include the shared_ptr in std:tr1 on gcc? the file i looked in said not to include it directly, from what i can tell no other file includes it either :|
| In G++ 4.3,
#include <tr1/memory>
should do the trick. You'll find shared_ptr at std::tr1::shared_ptr.
|
472,015 | 472,028 | new on stack instead of heap (like alloca vs malloc) | Is there a way to use the new keyword to allocate on the stack (ala alloca) instead of heap (malloc) ?
I know I could hack up my own but I'd rather not.
| To allocate on the stack, either declare your object as a local variable by value, or you can actually use alloca to obtain a pointer and then use the in-place new operator:
void *p = alloca(sizeof(Whatever));
new (p) Whatever(constructorArguments);
However, while using alloca and in-place new ensures that the memory ... |
472,329 | 472,365 | How can I synchronize two processes accessing a file on a NAS? | Here's the thing: I have two applications, written in C++ and running on two machines with different OS (one Linux and one Windows). One of this process is in charge of updating an XML file on a NAS (Network Attached Storage) while the other one reads this file.
Is it possible to synchronize these two processes in ord... | You could create a lock file on the server that is created before you do a write, wait then write and delete on completion., Have the read process check for the token before reading the file.
Edit: To address the comments, you can implement a double-checked locking type pattern. Have both reader and writer have a locki... |
472,393 | 472,399 | Cache, loops and performance | Some time ago I wrote a little piece of code to ask about on interviews and see how people understand concepts of cache and memory:
#include "stdafx.h"
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#define TOTAL 0x20000000
using namespace std;
__int64 count(int INNER, int OUTER)
{
int a = 0;
i... | Probably because 64 is the cache line size on your machine, and you basically run each iteration fully out of a single cache line.
|
472,530 | 472,750 | How to pass an array size as a template with template type? | My compiler behaves oddly when I try to pass a fixed-size array to a template function. The code looks as follows:
#include <algorithm>
#include <iostream>
#include <iterator>
template <typename TSize, TSize N>
void f(TSize (& array)[N]) {
std::copy(array, array + N, std::ostream_iterator<TSize>(std::cout, " "));
... | Hmm, the Standard says in 14.8.2.4 / 15:
If, in the declaration of a function template with a non-type template-parameter, the non-type template-parameter is used in an expression in the function parameter-list and, if the corresponding template-argument is deduced, the template-argument type shall match the type of t... |
472,667 | 472,683 | Lambda expressions support in VS2008 SP1 | Is there support for lambda expressions from C++ 0x in Visual Studio 2008 SP1? Example below throws me syntax errors. Is there any '-Cpp0x' flag for compiler or something?
#include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
for (int i = ... | See Stackoverflow question #146381
Simply put: no. Visual Studio 2010 will support C++0x to some extent, but I'm unsure if that will include lambda expressions.
|
472,791 | 473,353 | How to create a filled arrow CustomLineCap? | The MSDN documentation has several open arrow examples but no examples for filled arrows.
I just want to create a bigger arrow than the default LineCapArrowAnchor. I tried several things and can't get it to work. It should be simple, right?
| Found it. Looks like there's an AdjustableArrowCap class that derives from CustomLineCap and does just what I wanted.
|
473,023 | 473,613 | Have you ever obtained a significant speedup by using boost::pool? | I've played with boost::pool a few times in places where it seemed to me I was seriously hammering the heap with a lot of object "churn". Generally I've used boost::object_pool, or boost::pool_alloc as an STL template parameter. However the result is invariably that performance is virtually unchanged, or significantl... | Memory pools are most effective imo for transaction style processing where you can allocate to the pool and then when the transaction is done, just dump it into oblivion. The real speed up isn't that each allocation is going to be much faster its that you will have near zero memory fragmentation in an extremely long ru... |
473,236 | 473,262 | Check for value definedness in C++ | I'm working in C++ and I need to know if a scalar value (for instance a double) is "defined" or not. I also need to be able to "undef" it if needed:
class Foo {
public:
double get_bar();
private:
double bar;
void calculate_bar() {
bar = something();
}
};
double Foo::get_bar() {
if ( undefi... | As the other answers says, C++ doesn't have this concept. You can easily work around it though.
Either you can have an undefined value which you initialize bar to in the constructor, typically -1.0 or something similar.
If you know that calculate_bar never returns negative values you can implement the undefined functio... |
473,623 | 475,660 | Sphere World Implementation C++ | What would be the best way to implement, store, and render spherical worlds, such as the ones in spore or infinity but without the in-between stages of spore, and multiple worlds ala infinity universe. Make no assumptions on how the planet itself is generated or its size/scale.
| For rendering, you'll need to use some sort of level-of-detail algorithm in order to seamlessly move from close to the planet's surface to far away. There are many dynamic LOD algorithms (see here). An older algorithm, called ROAM, can be adapted to handle spherical objects, or planets (spherical ROAM). Geometry clipma... |
473,662 | 473,677 | I see many examples of C++ with the use of "Foo ^ bar" - what is "^"? | Is that .NET related?
It appears to be a pointer of some sort, what is the difference?
Edit:
I actually know it is the XOR operator, but look at this example from this page.
void objectCollection() {
using namespace System::Collections;
**ArrayList ^as = gcnew ArrayList;**
//... }
What is this?
Thanks.
| I'm assuming that you're looking at constructs of the form:
Foo ^bar = gcnew Foo();
You're right, in .NET it is a pointer-"like" type and is part of C++/CLI, not but not standard ISO C++.
It's a reference to a garbage-collected, managed .NET object as opposed to a regular, unmanaged C++ object.
As the other poster sug... |
473,720 | 473,753 | Why is the destructor ignored in this code? | The following code demonstrates a weird problem I have in a Turbo C++ Explorer project. One of the three stack objects in D::D() is not destroyed after going out of scope.
This only happens if compiled in release mode, the auto_ptrs a_ and b_ are of different types and the exception thrown doesn't inherit from std::ex... | This appears to be a compiler bug. I just ran the same sample in VS2008SP1 and got the expected output.
|
473,915 | 473,929 | Should I make my own framework? | Should I make my own framework by wrapping up the STL classes and/or Boost libraries so that if I need to change the implementation of the string, vectors, lists, etc. or I need to write functions that MFC, other other libraries or even other platforms would need to use their format, I can easily mutate them to meet th... | It seems to me like there won't be a lot of benefit to this; in my experience, the point of using these frameworks is so that you don't go reinventing the wheel. If you find that you need to write a new string class or a new vector class, you should think really hard about it, and make sure you're not just doing someth... |
473,958 | 473,974 | Memory management in memory intensive application | If you are developing a memory intensive application in C++ on Windows, do you opt to write your own custom memory manager to allocate memory from virtual address space or do you allow CRT to take control and do the memory management for you ? I am especially concerned about the fragmentation caused by the allocation a... | I think your best bet is to not implement one until profiles prove that the CRT is fragmenting memory in a way that damages the performance of your application. CRT, core OS, and STL guys spend a lot of time thinking about memory management.
There's a good chance that your code will perform quite fine under existing... |
474,007 | 474,058 | Floating Point to Binary Value(C++) | I want to take a floating point number in C++, like 2.25125, and a int array filled with the binary value that is used to store the float in memory (IEEE 754).
So I could take a number, and end up with a int num[16] array with the binary value of the float:
num[0] would be 1
num[1] would be 1
num[2] would be 0
num[3] w... | Use union and bitset:
#include <iostream>
#include <bitset>
#include <climits>
int main()
{
union
{
float input; // assumes sizeof(float) == sizeof(int)
int output;
} data;
data.input = 2.25125;
std::bitset<sizeof(float) * CHAR_BIT> bits(data.output);
std::cout << bits << st... |
474,279 | 474,378 | Retaining functors as variables | I'm working on a resource management class and want to have the user provide a functor to a "ReleaseResource" method as part of the resource manager's constructor. From there when a resource is requested that functor will be provided as the deleter for the shared_ptr that I will be returning so that the appropriate met... | template<class MyFunctor> MyMethod(MyFunctor f) {
boost::function<void()> g = f;
g();
}
The type you pass to boost::function is the function type. For example, int(bool, char) is the type of a function returning int and taking a bool and a char. That said, if you want to construct the shared_ptr right away, yo... |
474,521 | 477,992 | What API to use for adding HTTP client support in an existing MFC app? | I have recently been given a task to add the ability to interact with Web Map Services to an existing MFC application and I am in need of a client-side HTTP API.
Based on my research, the leading candidates seem to be CAtlHttpClient and WinHTTP. I was curious to see if anyone had experiences they could share or opin... | The simplest one is the WinInet MFC wrappers: CInternetSession and friends.
WinHTTP, although a different API, is built on the same model as WinInet yet provides better HTTP support (no FTP though but you probably don't care). Whether you need the extra goodies provided by WinHTTP should be examined.
A down side of Wi... |
474,840 | 474,855 | boost vs ACE C++ cross platform performance comparison? | I am involved in a venture that will port some communications, parsing, data handling functionality from Win32 to Linux and both will be supported. The problem domain is very sensitive to throughput and performance.
I have very little experience with performance characteristics of boost and ACE. Specifically we wan... | Neither library should really have any overhead compared to using native OS threading facilities. You should be looking at which API is cleaner. In my opinion the boost thread API is significantly easier to use.
ACE tends to be more "classic OO", while boost tends to draw from the design of the C++ standard library. Fo... |
474,867 | 474,921 | Counting the number of methods defined in a C++ header | Is there a tool to count the number of methods defined in a header? This seems like something that people would want to do from time to time, but I've never heard of such a utility. I could roll my own (and it'd be quite easy to come up with something that works for me in this particular case), but I thought I'd try st... | Try this:
ctags --c++-kinds=f -x myfile.h
To list all functions in the file myfile.h . To count the number of functions in deque.tcc:
$ ctags --c++-kinds=f --language-force=c++ -x deque.tcc | wc -l
24
|
475,301 | 475,342 | Tools for automatically generating unit tests for C++? | We have a large amount of legacy C++ code in shared libraries that are used on dozens of products. Ignoring the pros and cons of automatically generating tests (that's a discussion for another day), does anyone have any recommendations for a tool that would analyse the source and generate a set of tests to exercise tha... | I've heard Parasoft mentioned a few times. I've never used their products, but the article "Change Software Without Fear" (written by one of their employees) covers automatic test generation ("behavioral regression testing," they call it) in a non-salesy fashion and touches briefly on their software.
|
475,570 | 475,601 | Shared Library Discovery | I am using C++ on Linux. I want to dynamically bind a collection of unknown shared libraries. I need my code to detect all the public functions exposed by the shared library and the string names of those functions. How do I accomplish this task?
| AFAIK, there is no glibc function to enumerate all the public interface functions for a .so file. You can refer to libelf to read all symbols from a dynamic file. Libelf is here http://www.mr511.de/software/. After you find a symbol, you can use dlopen and dlsym to load it.
|
475,619 | 475,695 | C++0x implementation guesstimates? | The C++0x standard is on its way to being complete. Until now, I've dabbled in C++, but avoided learning it thoroughly because it seems like it's missing a lot of modern features that I've been spoiled by in other languages. However, I'd be very interested in C++0x, which addresses a lot of my complaints. Any guesst... | I see no reason why C++0x shouldn't be adopted. The C++ community is much more forward-looking than C. C was always meant to be a "portable assembler language", so people who use that aren't really super interested in fancy new features. C++ spans much wider, and I've yet to hear of a C++ programmer who wasn't looking ... |
475,824 | 475,831 | static_cast<int>(foo) vs. (int)foo | Could somebody please elaborate on the differences?
| The difference is that (int)foo can mean half a dozen different things.
It might be a static_cast (convert between statically known types), it might be a const_cast (adding or removing const-ness), or it might be a reinterpret_cast (converting between pointer types)
The compiler tries each of them until it finds one t... |
475,850 | 475,951 | Converting UTF-8 to WIN1252 using C++Builder 5 | I have to import some UTF-8 encoded text-file into my C++Builder 5 program.
Are there any components or code samples to accomplish that?
| You are best off reading all the other questions on SO that are tagged unicode and c++. For starters you should probably look at this one and see whether library in the accepted answer (UTF8-CPP) works for you.
I would however first think about what you're trying to achieve, as there is no way you can just import UTF-8... |
475,853 | 476,014 | Can I use CreateFile, but force the handle into a std::ofstream? | Is there any way to take advantage of the file creation flags in the Win32 API such as FILE_FLAG_DELETE_ON_CLOSE or FILE_FLAG_WRITE_THROUGH as described here http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx , but then force that handle into a std::ofstream?
The interface to ofstream is obviously platform in... | It is possible to attach a C++ std::ofstream to a Windows file handle. The following code works in VS2008:
HANDLE file_handle = CreateFile(
file_name, GENERIC_WRITE,
0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (file_handle != INVALID_HANDLE_VALUE) {
int file_descriptor = _open_osfhandle((i... |
475,888 | 475,927 | Will this lead to a memory leak in C++? | I have a C++ memory management doubt, that's (obviously) related to references and pointers. Suppose I have a class Class with a method my_method:
OtherClass& Class::my_method( ... ) {
OtherClass* other_object = new OtherClass( ... );
return *other_object;
}
Meanwhile in a nearby piece of code:
{
Class m( ... | It's fairly obvious that you want to return a new object to the caller that you do not need to keep any reference to. For this purpose, the simplest thing to do is to return the object by value.
OtherClass Class::my_method( ... ) {
return OtherClass( ... );
}
Then in the calling code you can construct the new obje... |
475,973 | 475,977 | How to load digital signals from a USB port into memory? | My friend is working on a project in which he needs to get some digital signals into a computer to display/manipulate them.
So I advised him to insert those signals into a USB port due to it's popularity (because the device (which outputs the signals) and the program used for display and manipulation should both be des... | There is a great article here: USB hardware/software integration that describes the process in full.
|
476,043 | 476,048 | Is there a way to call an unmanaged (not COM) dll from C# application? | Is there a way to use (reference) a DLL written in an unmanaged C++ (not a COM library) in my C# application?
When I try to reference it from within Visual Studio, I get 'not a COM object' error message.
Maybe there is some kind of translator\router that would COMify my DLL reference?
I have no clue how COM and COM int... | You need to use the DllImport attribute. Here's an example for the Win32 PostMessage function:
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool PostMessage(IntPtr handle, int message, IntPtr wparam, IntPtr lparam);
|
476,212 | 476,225 | What is the precision of long double in C++? | Does anyone know how to find out the precision of long double on a specific platform? I appear to be losing precision after 17 decimal digits, which is the same as when I just use double. I would expect to get more, since double is represented with 8 bytes on my platform, while long double is 12 bytes.
Before you as... | You can find out with std::numeric_limits:
#include <iostream> // std::cout
#include <limits> // std::numeric_limits
int main(){
std::cout << std::numeric_limits<long double>::digits10 << std::endl;
}
|
476,272 | 476,279 | How to properly overload the << operator for an ostream? | I am writing a small matrix library in C++ for matrix operations. However my compiler complains, where before it did not. This code was left on a shelf for 6 months and in between I upgraded my computer from debian etch to lenny (g++ (Debian 4.3.2-1.1) 4.3.2
) however I have the same problem on a Ubuntu system with the... | You have declared your function as friend. It's not a member of the class. You should remove Matrix:: from the implementation. friend means that the specified function (which is not a member of the class) can access private member variables. The way you implemented the function is like an instance method for Matrix cla... |
476,461 | 476,465 | Programming style of method declaration of get/set method variables in C++? | Should you declare the getters/setters of the class inside the .h file and then define them in .cpp Or do both in .h file. Which style do you prefer and why? I personally like the latter wherein all of them are in .h and only methods which have logic associated with it other than setters/getters in .cpp.
| For me it depends on who's going to be using the .h file. If it's a file largely internal to a module, then I tend to put the tiny methods in the header. If it's a more external header file that presents a more fixed API, then I'll put everything in the .cpp files. In this case, I'll often use the PIMPL Idiom for a ... |
476,488 | 476,507 | How to use std::foreach with parameters/modification | I've found myself writing
for(int i=0;i<myvec.size();i++)
myvec[i]->DoWhatever(param);
a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things like
for(int i=0;i<myvec.size();i++)
if(myvec[i]->IsOK())
myvec[... | #include <vector>
#include <algorithm>
#include <functional>
class X
{
public:
void doWhat(int x) {}
bool IsOK() const {return true;}
};
class CallWhatIfOk
{
public:
CallWhatIfOk(int p): param(p) {}
void operator()(X& x) const
{ if (x.IsOK()) {x.doWhat(param);}}
... |
476,800 | 476,834 | Comparing two integers without any comparison | Is it possible to find the greatest of two integers without any comparison? I found some solutions:
if(!(a/b)) // if a is less than b then division result will be zero.
{
cout << " b is greater than a";
}
else if (!(a-b)) // we know a is greater than or equal to b now. check whether they are equal.
{
cout <<... | Subtract them and check the sign using nasty bit twiddling hacks
http://graphics.stanford.edu/~seander/bithacks.html
Don't do this in production code if the other programmers know where you live.
|
477,225 | 477,252 | Is std::ifstream significantly slower than FILE? | I've been informed that my library is slower than it should be, on the order of 30+ times too slow parsing a particular file (text file, size 326 kb). The user suggested that it may be that I'm using std::ifstream (presumably instead of FILE).
I'd rather not blindly rewrite, so I thought I'd check here first, since my ... | I don't think that'd make a difference. Especially if you're reading char by char, the overhead of I/O is likely to completely dominate anything else.
Why do you read single bytes at a time? You know how extremely inefficient it is?
On a 326kb file, the fastest solution will most likely be to just read it into memory ... |
477,331 | 477,353 | How to use the "removed" elements after std::remove_if | Say we've got:
struct IsEven {
bool operator() (int i) { return i % 2 == 0; }
};
Then:
vector<int> V; // fill with ints
vector<int>::iterator new_end = remove_if(V.begin(), V.end(), IsEven());
V.erase(new_end, V.end());
works fine (it leaves V with only the odd integers). But it seems that the elements from new_en... | It sounds like you want to use partition() to partition the vector into groups of odd values at the start and even values at the end. partition() will return an iterator to the first element of the second grouping.
As for the WTF, I'm not sure why you would expect a remove operation to preserve the elements you want t... |
477,427 | 477,436 | c++ ifstream, detect if letter or EOLine? | I have this function to read in all ints from the file.
The problem is when i read letters i trigger a new line and i always seek by 1 and not to the end of line. How can i write this function better?
int v;
while (!in.eof())
{
while (in >> v)
cout << v << " ";
cout << endl;
... | If your file consists of just ints separated by whitespace (including) newlines then this should be sufficient.
while( in >> v )
{
// do something with v
}
After the file, if in.fail() is false and in.eof() is true, then you reached the end of the file without a formatting error. Otherwise an error reading an int ... |
477,452 | 477,481 | Coding practice: return by value or by reference in Matrix multiplication? | I'm writing this question with reference to this one which I wrote yesterday. After a little documentation, it seems clear to me that what I wanted to do (and what I believed to be possible) is nearly impossible if not impossible at all. There are several ways to implement it, and since I'm not an experienced programme... | The problem you are having is that the expression a * b creates a temporary object, and in C++, a temporary is not allowed to bind to a non-constant reference, which is what your Matrix& operator=(Matrix& m) takes. If you change it to:
Matrix& operator=(Matrix const& m);
The code should now compile. As well as the o... |
477,461 | 477,466 | When building a DLL file, does the generated LIB file contain the DLL name? | In Visual C++ , when I build a dll , the output files are .dll and .lib.
Is the name of the dll built into the .lib file .
The reasson I ask this question is : When I built my exe by importing this dll and run the exe , the exe tries to locate the dll to load it in the process address space .
As we just specify the l... | The LIB file is turned into an import table in the EXE. This does contain the name of the DLL.
You can see this if you run dumpbin /all MyDLL.lib. Note that dumpbin MyDll.lib by itself doesn't show anything useful: you should use /all.
This shows all of the sections defined in the .LIB file. You can ignore any .debug s... |
477,503 | 477,517 | Mounting folder as a drive in vista | Hi I am trying to mount as a drive in vista I am using the following code from msdn example,
BOOL bFlag;
TCHAR Buf[BUFSIZE]; // temporary buffer for volume name
if( argc != 3 )
{
_tprintf( TEXT("Usage: %s <mount_point> <volume>\n"), argv[0] );
_tprintf( TEXT("For example, \"%s c:\\mnt\\f... | SetVolumeMountPoint is for mounting a volume on a drive letter or in a folder. It does not allow you to mount a folder on a drive letter. This is the opposite of what you want.
To make a folder available as a drive letter, you want to do the equivalent of the SUBST utility. This uses DefineDosDevice, something like thi... |
477,525 | 477,558 | Expression Evaluation in C++ | I'm writing some excel-like C++ console app for homework.
My app should be able to accept formulas for it's cells, for example it should evaluate something like this:
Sum(tablename\fieldname[recordnumber], fieldname[recordnumber], ...)
tablename\fieldname[recordnumber] points to a cell in another table,
fieldname[rec... | Ok, nice homework question by the way.
It really depends on how heavy you want this to be. You can create a full expression parser (which is fun but also time consuming).
In order to do that, you need to describe the full grammar and write a frontend (have a look at lex and yacc or flexx and bison.
But as I see your q... |
477,787 | 477,836 | C++, windows->linux porting, mapfile problem | I'm porting a small C++ console application from windows to linux, GCC 4.3.2. When compiling I get strange error that I'm unable to solve.
Labels.cpp: In function ‘void DumpSymbols()’:
Labels.cpp:68: error: invalid conversion from ‘int’ to ‘std::_Ios_Openmode’
Labels.cpp:68: error: initializing argument 2 of ‘std::ba... | Just remove "|ios::beg":
ofstream mapfile("symbols.map", ios::out);
It's type is ios_base::seekdir, which is not an opening mode; it's for seeking to a position. You'll automatically be at the beginning anyway.
|
477,829 | 477,868 | cannot call base class protected functions? | I cant call protected function in my base class. Why? It looks something like this:
class B : B2
{
public:
virtual f1(B*)=0;
protected:
virtual f2(B*) { codehere(); }
}
class D : public B
{
public:
virtual f1(B*b) { return f2(b); }
protected:
virtual f2(B*b) { return b->f2(this); }
}
In msvc I get the error er... | Protected member functions can only be called inside the base class or in its derived class. You cannot call them outside your class. Outside calling means calling a member function of a class-typed variable.
So
virtual f1(B*b) { return f2(b); }
is ok, because f2 operates on the class itself. (called inside)
But
virtu... |
477,885 | 477,889 | Visual C++ express 2008: Why does it places megs of null bytes at the end of the release executable? | Recently I have discovered that my release executable (made with msvc++ express 2008) becomes very large. As I examine the executable with a hex viewer I saw that only the first 300k bytes contains useful data the remaining bytes are only zeros - 6 megs of zero bytes.
The debug built exe has 1MB size, but the release i... | Did you define large arrays at file-scope in your program? That might be one reason. You can use the dumpbin program to see how much space each section in the exe file takes, that should give you a clue to the "why".
|
477,945 | 477,996 | POCO C++ libraries on CDT | I am working with CDT (C/C++ for eclipse) on windows, and I need to start using POCO C++ libraries
The current package distribution for POCO requires MS Visual Studio 7/8/9 for compiling the libs.
Does anyone know a solution for compiling in a CDT environment on windows? I am using MinGW for compile/build tools.
| It is possible to use POCO with MinGW - some folks already do this successfully. I would first try to get going with MinGW alone, and when this works, integrate it into Eclipse (which shouldn't be too hard.).
There are some patches and bug reports in POCO's tracker on SourceForge. Looking at them will certainly help (h... |
478,037 | 478,041 | How can I make the program I wrote with QT4 execute when I launch it not from IDE? | When I run the program from IDE (VS2008) it works perfectly. When I want to launch it from Windows Commander it doesn't work because it needs DLL that wasn't found.
Used both debug and release builds.
| Make sure the Qt DLL's are in your PATH. Two simple solutions are:
Copy Qt's DLL's to your EXE's directory.
Copy Qt's DLL's to %WINDOWS%\System32 (e.g. C:\WINDOWS\System32) (possibly unsafe, especially if you install another versions of Qt system-wide. Also, requires administrative privilages).
|
478,075 | 478,088 | Creating files in C++ | I want to create a file using C++, but I have no idea how to do it. For example I want to create a text file named Hello.txt.
Can anyone help me?
| One way to do this is to create an instance of the ofstream class, and use it to write to your file. Here's a link to a website that has some example code, and some more information about the standard tools available with most implementations of C++:
ofstream reference
For completeness, here's some example code:
// usi... |
478,165 | 478,271 | How to create an efficient 2D grid in C++? | I want to create a really easy to use 2D Grid. Each cell in the grid needs to be able to store a load of data. Ideally I would like to be able to traverse through the grid one cell at a time, as well as obtain the immediate neighbours of any of the grid cells.
My first thought was to store a vector of pointers to a Cel... | If you want a four-direction iterator, make your own:
template<typename T, int width, int height>
class Grid {
public:
T data[width * height];
iterator begin() {
return iterator(data);
}
iterator end() {
return iterator(data + width * height);
}
... |
478,298 | 478,314 | How do I write a C++ program that will easily compile in Linux and Windows? | I am making a C++ program.
One of my biggest annoyances with C++ is its supposed platform independence.
You all probably know that it is pretty much impossible to compile a Linux C++ program in Windows and a Windows one to Linux without a deluge of cryptic errors and platform specific include files.
Of course you can a... | The language itself is cross-platform but most libraries are not, but there are three things that you should keep in mind if you want to go completely cross-platform when programming in C++.
Firstly, you need to start using some kind of cross-platform build system, like SCons. Secondly, you need to make sure that all o... |
478,482 | 478,550 | Express the usage of C++ arguments through method interfaces | Is there a common way to express the usage of arguments in C++? I want to implicitly tell the consumers of my class how the arguments they pass will be used by the class.
Examples:
I own your argument (will clean it up)
I will hold a reference to your argument during my lifetime (so you should NOT delete it while I'm... | Our team has similar coding conventions to the ones you suggest:
1 - auto_ptr argument means that the class will take control of memory management for the object. (We don't use this much.)
2 - shared_ptr means that the class will probably use the argument for an extended period of time, and in particular may store off... |
478,668 | 479,127 | Boost Serialization using polymorphic archives | I am working on a client-server application that uses boost::serialization library for it's serialization needs.
I need to serialize and deserialize polymorphic objects that does not seem to work. The documentation does say that it is supported but none of the related examples demonstrate what I'm trying to do here. ... | Found a resolution. I had to export the derived class with the statement:
BOOST_CLASS_EXPORT(derived);
Posting something that works with some corrections.
using namespace std;
class base {
public:
int data1;
friend class boost::serialization::access;
template<typename Archive>
void ser... |
478,725 | 485,909 | Why is the OO concept interface not represented by a keyword in C++? | Languages such as Java explicitly use the interface keyword to denote interfaces. Having used Java, the concept seems useful enough to me to justify a keyword to enforce the concept.
Of course one can use a pure virtual class and label it as an interface. However, this keyword seems to be so useful and differentiated... | The early OO features of C++ have long been neglected because it has since moved in a more interesting direction as a multi-paradigm language. The major focus for over a decade now has been templates and their implications, particularly in the standard library. Yes, programs would be more readable with an interface key... |
478,898 | 478,960 | How do I execute a command and get the output of the command within C++ using POSIX? | I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example of what I'm looking for:
std::string result = system("./some_command");
I need to run an arbitrary command and get its o... | #include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
std::string exec(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::r... |
478,911 | 478,964 | Silverlight and C++ or C++ to C# ongoing code conversion? | I am working on a drawing-based product where I want to produce versions for iPhone, desktop OS/X, Windows Tablets, Silveright-based browser, Windows Mobile, and Windows in that order of priority.
For GUI portability, the classic answer is to keep the core in C++ and use Cocoa/Objective-C or WPF/C# thin layers.
However... |
Architectural separation of the Silverlight version so the C++ logic remains on a server. I'm a bit uncomfortable about the performance implications.
I'd do this. The performance is probably not as bad as you imagine.
|
478,967 | 478,986 | C++ Array Member of Constant Length (Initialisation of) | I have a class that contains an array. I want this array to be set at the length of a constant:
// Entities.h
class Entities
{
private:
const int maxLimit;
int objects[maxLimit];
int currentUsage;
public:
Entities();
bool addObject(in... | The array must have a constant length. I mean a length that is the same for all objects of that class. That is because the compiler has to know the size of each object, and it must be the same for all objects of that particular class. So, the following would do it:
class Entities
{
private:
static const... |
479,080 | 479,256 | trim is not part of the standard c/c++ library? | Is it me or are there no standard trim functions in the c or c++ library? is there any single function that acts as a trim? If not can anyone tell me Why trim is not part of the standard library? (i know trim is in boost)
My trim code is
std::string trim(const std::string &str)
{
size_t s = str.find_first_not_of(" ... | The reason trim() isn't in the standard library is that when the last standard was made, they had to strike a balance between formalizing current behavior (adding nothing new, just stabilizing what already existed), and adding new functionality. In general, they preferred not to add a feature unless it either 1) would ... |
479,312 | 479,336 | product to decrease c++ compile time? | Are there any products that will decrease c++ build times? that can be used with msvc?
| If it has to be a product, look at Xoreax IncrediBuild, which distributes the build to machines on the network.
Other than that:
solid build machines. RAM as it fits, use fast separate disks.
Splitting into separate projects (DLLs, Libraries). They can build in parallel, too
(use dual quad/core, and is easily bottlen... |
479,332 | 479,507 | How to get size and position of window caption buttons (minimise, restore, close) | Is there an API call to determine the size and position of window caption buttons? I'm trying to draw vista-style caption buttons onto an owner drawn window. I'm dealing with c/c++/mfc.
Edit: Does anyone have a code example to draw the close button?
| I've found the function required to get the position of the buttons in vista: WM_GETTITLEBARINFOEX
This link also shows the system metrics required to get all the spacing correct (shame it's not a full dialog picture though). This works perfectly in Vista, and mostly in XP (in XP there is slightly too much of a gap bet... |
479,384 | 479,386 | c++ cout autocase strings? | Is it possible to do something like cout << "my string"; and have my string capitalized? from what i can tell there is no way to do it? i need to wrap it around a function
| Yes, you can extend std:streambuf
See this example: http://www.java2s.com/Tutorial/Cpp/0240__File-Stream/Extendsstdstreambuftocreateoutputbuffer.htm
|
479,431 | 516,642 | Unit-tests for Boost.Spirit | I'm new to Boost.Spirit and Boost.Test and I would like to know how you verify the correctness of your grammars. Below is a simplified version of how I do it at the moment and I'm pretty sure that there's a better way:
Each test case hase a pair of two strings containing the text to parse and the expected result delimi... | In general, your approach seems fine to me. I would probably group class of tests into function with descriptive names, e.g. TestInvalidGrammar, TestErrorHandling, TestNestedGrammar etc. and have those called from the main.
I am sure you have read documentation but take a look at examples if it helps.
|
479,495 | 480,126 | Visual Studio 2005 VB debugging with c++ dll - Mixed Language debugging | I have a vb project which calls functions in a dll.
The dll is created in a separate vs project (portaudio), which is written in c.
The dll c project compiles clean and builds the required dll, which I am currently dropping in c:\windows\system to vb runtime can see it.
VB Project lives in c:\devprojects\vbtest
C Proj... | It is not necessary to have both projects in the same solution, but you should compile both projects with debug symbols enabled.
Now in your VB net solution Project/Properties, in the Debug tab make sure that "Enable unmanaged code debugging" is checked.
Also make sure that the dll loaded is in the same place where it ... |
479,634 | 479,930 | Detect executable folder from SDL | I am creating a C++ SDL game engine, and it is relevant to know the executable path since images and other resources are not stored within the executable - they are in a separated folder("res/").
Under Linux, I am using a shell script "rungame.sh" that cd's to the executable path and then runs the executable(using then... | I strongly suggest searching before posting: How do I get the directory that a program is running from?
|
479,722 | 486,909 | How to get current CPU and RAM usage in C++? | is it possible, in C++, to get the current RAM and CPU usage? Is there a platform-indepentent function call?
| There is an open source library that gives these (and more system info stuff) across many platforms: SIGAR API
I've used it in fairly large projects and it works fine (except for certain corner cases on OS X etc.)
|
479,805 | 480,896 | Visual C++ 2008 Express Edition error creating a new project | I have installed Visual C++ 2008 Express Edition on Vista Home Premium and whenever i try to create a new project, no mater which type(CLR, Console, Win32, Empty project) i get "Creating project 'project name' ... project creation failed." However i can open an existing solution.
So basically my Visual C++ is useless. ... | Solved following the steps in this guide: http://masteranza.wordpress.com/2008/12/27/solution-vs-c-2008-project-creation-failed-bug/ after a lot of Googleing
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.