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 |
|---|---|---|---|---|
2,539,077 | 2,539,181 | BOOST program_options: parsing multiple argument list | I would like to pass the multiple arguments with positive or negative values.
Is it possible to parse it?
Currently I have a following initialization:
vector<int> IDlist;
namespace po = boost::program_options;
po::options_description commands("Allowed options");
commands.add_options()
... | Have you tried "-2"?
Edit: Quoting doesn't seem to do the trick, however, changing the command line style works:
char* v[] = {"name","--IDlist=0","1","200","-2"};
int c = 5;
std::vector<int> IDlist;
namespace po = boost::program_options;
po::options_description commands("Allowed options");
commands.add_options()... |
2,539,081 | 2,539,086 | Could the assign function for containers possibly overflow? | I ran into this question today and thought I should post it for the community's reference and/or opinions.
The standard C++ containers vector, deque, list, and string provide an assign member function. There are two versions; I'm primarily interested in the one accepting an iterator range. The Josuttis book is a litt... | Here's what I found. It turns out I didn't have to worry about silently doing the wrong thing. Once again, the standard has the answer. From section 23.2.6.1:
void assign(Iter first, Iter last);
Effects:
erase(begin(), end());
insert(begin(), first, last);
So it's really just a shortcut for a clear() followed by a... |
2,539,088 | 2,557,640 | 3D coordinate of 2D point given camera and view plane | I wish to generate rays from the camera through the viewing plane. In order to do this, I need my camera position ("eye"), the up, right, and towards vectors (where towards is the vector from the camera in the direction of the object that the camera is looking at) and P, the point on the viewing plane. Once I have thes... | When I directly plugged in suggested formulas into my program, I didn't obtain correct results (maybe some debugging needed to be done). My initial problem seemed to be in the misunderstanding of the (x,y,z) coordinates of the interpolating corner points. I was treating x,y,z-coordinates separately, where I should not ... |
2,539,113 | 2,539,189 | C++ ulong to class method pointer and back | I'm using a hash table (source code by Google Inc) to store some method pointers defined as:
typedef Object *(Executor::*expression_delegate_t)( vframe_t *, Node * );
Where obviously "Executor" is the class.
The function prototype to insert some value to the hash table is:
hash_item_t *ht_insert( hash_table_t *ht, ul... | If I remember correctly, a class method pointer may be larger than a normal function pointer due to implementation details. This would explain why the compiler does not allow this cast – the method pointer wouldn’t fit inside the storage space of a “normal” pointer.
The solution, as I’ve stated above in a comment, is t... |
2,539,164 | 2,539,225 | How to link app with static library + why this is not working | I have a problem. I wrote example code and I want to build it without the error:
main.cpp(.text+0x5): undefined reference to `test()'
Library
test1.c
#include <stdlib.h>
void test()
{
puts("Działa");
}
test1.h
#ifndef TEST1_H
#define TEST1_H
extern void test();
#endif
makefile
all:
gcc -c ./src/test1.c -o ./lib... | You are compiling a C code function, but you are expecting to link a C++ function.
Because of 'type safe linkage', the function you provide is not the function that the C++ code calls.
Either in test1.h use:
#ifdef __cplusplus
extern "C" {
#endif
extern void test1(void);
#ifdef __cplusplus
}
#endif
Or:
Compile the ... |
2,539,458 | 2,539,501 | C++ -- return x,y; What is the point? | I have been programming in C and C++ for a few years and now I'm just now taking a college course in it and our book had a function like this for an example:
int foo(){
int x=0;
int y=20;
return x,y; //y is always returned
}
I have never seen such syntax. In fact, I have never seen the , operator used outside of... | The comma operator is primarily used in for statements like so:
for( int i=0, j=10; i<10; i++, j++ )
{
a[i] = b[j];
}
The first comma is not a comma operator, it's part of the declaration syntax. The second is a comma operator.
|
2,539,555 | 2,554,702 | Directly Jump to another C++ function | I'm porting a small academic OS from TriCore to ARM Cortex (Thumb-2 instruction set). For the scheduler to work, I sometimes need to JUMP directly to another function without modifying the stack nor the link register.
On TriCore (or, rather, on tricore-g++), this wrapper template (for any three-argument-function) works... | Well, I now figured out what went wrong.
The whole concept of JUMPing directly to another function is moot on ARM Cortex, because TriCore uses a Context Save Area (CSA) to save the whole CPU context everytime you call another function. Think of it as a second, independent stack that grows with each CALL and shrinks wi... |
2,539,709 | 2,539,737 | C++ list<T>::iterator cant be used in derived class template | g++ compiler gives this error: expected `;' before 'it'
template <typename T>
class myList : public std::list<T>
{
public:
void foo ()
{
std::list<T>::iterator it; // compiler error as above mentioned, why ???
}
};
Thanks.
| In g++. whenever in a template you see the error:
error: expected ';' before 'it'
suspect you need a typename:
typename std::list<T>::iterator it;
This is needed when in a template you have a new type declared (in this case the list iterator) which is dependant on one or more of the template parameters. The need is... |
2,539,724 | 2,540,333 | WOW64: get x64 %CommonProgramFiles% from 32 bit process | Queries I tried: ExpandEnvironmentStrings("%COMMONPROGRAMFILES%"), GetSpecialPath(CSIDL_PROGRAM_FILES_COMMON).
All resolve to (typically) c:\\Program Files (x86)\\Common Files from my 32-bit app. I need to check a file version installed (typically) under c:\\Program Files\\Common Files of a 64-bit application.
| On 64-bit operating systems, the ProgramW6432 environment variable points to c:\program files. The full list for a 32-bit app on an English version of Windows:
ProgramFiles => c:\program files (x86)
ProgramFiles(x86) => c:\program files (x86)
ProgramW6432 => c:\program files
CommonProgramFiles => c:\program files (x8... |
2,539,812 | 2,539,876 | Refactor the following two C++ methods to move out duplicate code | I have the following two methods that (as you can see) are similar in most of its statements except for one (see below for details)
unsigned int CSWX::getLineParameters(const SURFACE & surface, vector<double> & params)
{
VARIANT varParams;
surface->getPlaneParams(varParams); // this is the line of code that is... | A couple ideas come to mind, but here's what I think would be best:
namespace detail
{
void getParameters(const SURFACE& surface, VARIANT& varParams)
{
surface->getPlaneParams(varParams);
}
void getParameters(const CURVE& curve, VARIANT& varParams)
{
curve->get_LineParams(varParams)... |
2,539,856 | 2,540,364 | Solving a difficult incomplete type error | I get an incomplete type error when trying to compile my code. I know that it is related to includes, but my project is large and it uses several templates so I can't find which type is actually incomplete. The error message doesn't help either:
Compiling: ../../../addons/ofxTableGestures/src/Graphics/objects/CursorFee... | It would be easier if you gave us the compiler.
On gcc you can see the preprocessed file using the -E option. If you try compiling the preprocessed file it should get much easier to diagnose. Furthermore you'll see exactly what are the types involved.
As for the specific error, the last line is generally the one indica... |
2,539,980 | 2,540,022 | Building an OpenCV application with Visual Studio 2008 and running it from another computer | I've made a simple OpenCV application with Visual Studio 2008 and I've built it in both release mode and debug mode.It works fine from my computer but when I try to run it from another computer which doesn't have OpenCV installed or has another version of Visual Studio with OpenCV it doesn't work.
How can I make the ap... | You don't need to distribute the libs; those are just needed for building the executable.
Just copy the dlls somewhere where the executable can see them (either in the same dir as the exe, or in a dir that's on the system path) and you should be golden.
|
2,540,126 | 2,540,154 | Problem separating C++ code in header, inline functions and code | I have the simplest code that I want to separate in three files:
Header file: class and struct declarations. No implementations at all.
Inline functions file: implementation of inline methods in header.
Code file: normal C++ code for more complicated implementations.
When I was about to implement an operator[] method... | Your main program file used to test your setup does not include the header file with the inline member functions. Since the functions are inline, they are not included in the object file produced from myclass.cpp.
The inline functions are not available to the compiler, so it thinks the calls are external; but they are ... |
2,540,218 | 2,540,301 | Get pixel's color in C++, Linux | I'm looking for a possibility to get the color of a pixel with given screen coordinates (x,y) in c++ / Linux? Maybe something similarly like getPixel() in Windows. I spent the whole day to find sth but without any success.
Thanks, Stefan
| See various different techniques posted at http://ubuntuforums.org/showthread.php?t=715256
|
2,540,246 | 2,540,278 | Xerces C++ SAX Parsing Problem: expected class-name before '{' token | I'm trying to run through an example given for the C++ Xerces XML library implementation. I've copied the code exactly, but I'm having trouble compiling it.
error: expected class-name before '{' token
I've looked around for a solution, and I know that this error can be caused by circular includes or not defining a cl... | Try adding using namespace xercesc; or explicitly specify the namespace for the Xerces classes (e.g. xercesc::HandlerBase).
Edit: There is also the XERCES_CPP_NAMESPACE_USE macro, which should be equivalent to the using statement.
|
2,540,602 | 2,540,619 | Does C# have a std::nth_element equivalent? | I'm porting some C++ code to C#.
Does C# have an equivalent to std::nth_element() or do I need to roll my own?
| I presume you are looking for an accessor that returns the Nth element of an unordered collection by performing a partial-sort on the collection. This tends to be useful when you have a very large collection and are interested in one of the first elements based on some ordering predicate.
To my knowledge, neither the .... |
2,540,607 | 2,541,344 | Can one class generate a signal and handled by another class? | I have a buffer in class 'bufferClass' that will generate a signal to tell 'fileClass' that buffer is full and now write data to file? And when 'fileClass' is done writing to file, it will generate a signal to tell 'guiClass' that data can be read from file.
Is this possible? I have been reading http://www.gnu.org/s/l... | I would use threading.
By having your main class 'fileClass' spin off a thread called 'bufferclass'. When buffer class exits succesfully you will know that your buffer is full.
Intermediate thread url below
http://www.cs.cf.ac.uk/Dave/C/node29.html
|
2,540,740 | 3,450,366 | Using SDL to replace colors using SDL Color Keys | I am working an a simple Roguelike game, and using SDL as the display. The Graphics for the game is an image of Codepage 437, with the background being black, and the font white. Instead of using many seperate image files that are already colored, I want to use one image file, and replace the colors when it is being ... | I solved this one a while back. The problem stemmed from doing the color keying in the wrong order. Here is the solved code:
uint8_t i;
uint8_t j;
uint8_t k = 0;
SDL_FillRect(Screen,NULL,0x00000000);
SDL_Rect Offset;
SDL_Surface *Load;
SDL_Surface *LoadFont;
Load = IMG_Load("resource/font.png");
LoadFont = SDL_Dis... |
2,540,742 | 2,540,973 | Count subset of binary pattern | I have a A=set of strings and a B=seperate string. I want to count the number of occurences in from B in A.
Example :
A:
10001
10011
11000
10010
10101
B:
10001
result would be 3.(10001 is a subset of 10001,10011,10101)
So i need a function that takes a set and string and returns an int.
int myfunc(set<string> , str... | If you have control over the input, and these strings are really supposed to represent bitmasks, then you probably want to keep them as integers of some sort and use bitmasks as suggested by others. Otherwise, if your stuck with dealing with them as strings, and you're going to use the same set of strings to search th... |
2,540,838 | 2,540,851 | C++ networking simple send and receive | I'm trying to link 10 computers together, the program I would like to write would have one 'control' computer. From what I've looked up this computer would take all the packets sent over the network and do a echo with them... right? The other computers would need to be able to send information (then echoed to the other... | http://beej.us/guide/bgnet/
In my opinion the unchallenged best guide to socket programming.
|
2,540,950 | 2,540,965 | Access an element in a set? | With a vector, I can do the following:
vector<int> myvec (4,100);
int first = myvec.at(0);
I have the following set:
set<int> myset;
myset.insert(100);
int setint = ????
How can I access the the element I inserted in the set?
| set<int>::iterator iter = myset.find(100);
if (iter != myset.end())
{
int setint = *iter;
}
|
2,541,175 | 2,541,189 | when to use c++ in managed versus unmanaged mode | I am wondering when I would use c++ in managed versus unmanaged mode?
Are there speed advantages with one mode over the other?
Is it easier to access 3rd party libraries in one mode over the other?
Are there any installation issues to worry about?
| I find that managed mode (C++/CLI) is primarily useful as a gateway facility that allows you to leverage legacy libraries. In short, I used it when I have to program in .Net, but need access to a C++ code base.
On its own, there's very little reason to choose C++/CLI over C#, which is cleaner, more modern, better-suppo... |
2,541,289 | 2,541,317 | Explicitly instantiating a generic member function of a generic structure | I have a structure with a template parameter, Stream. Within that structure, there is a function with its own template parameter, Type.
If I try to force a specific instance of the function to be generated and called, it works fine, if I am in a context where the exact type of the structure is known. If not, I get ... | You need to tell the compiler that the dependent name Printer<Stream>::Exec is a template:
out.template Exec<bool>(t);
It's the same principle as with typename, just that in this case the problematic name is not a type, but a template.
|
2,541,333 | 2,541,339 | What does the .. in #include "../somefile.h" mean | Does it mean search the previous folder for somefile.h or the project folder for somefile.h?
| It means that look for somefile.h in the parent folder with respect to the source file where the include directive is found.
In *nix systems(thats where this convention came from AFAIK):
. manse the current directory.
.. means one level up from the current directory.
For example, if you have the following... |
2,541,415 | 2,541,559 | creating QT gui using a thread in c++? | I am trying to create this QT gui using a thread but no luck. Below is my code. Problem is gui never shows up.
/*INCLUDES HERE...
....
*/
using namespace std;
struct mainStruct {
int s_argc;
char ** s_argv;
};
typedef struct mainStruct mas;
void *guifunc(void * arg);
int main(int argc, char * argv[]) {
mas ... | There appears to be two major issues here:
The GUI is not appearing because your main() function is completing after creating the thread, thus causing the process to exit straight away.
The GUI should be created on the main thread. Most frameworks require the GUI to be created, modified and executed on the main threa... |
2,541,433 | 2,541,509 | Split a Large File In C++ | I'm trying to write a program that takes a large file (of any type) and splits it into many smaller "chunks". I think I have the basic idea down, but for some reason I cannot create a chunk size over 12 kb. I know there are a few solutions on google, etc. but I am more interested in learning what the origin of this l... | You are writing to the split file, but not reading from the bigfile. What you are writing it the in-memory structure of the bigfile, not the contents of bigfile. You need to allocate a buffer, read into it from bigfile and write it to the splitfile(s).
|
2,541,446 | 2,541,549 | Exposing a pointer in Boost.Python | I have this very simple C++ class:
class Tree {
public:
Node *head;
};
BOOST_PYTHON_MODULE(myModule)
{
class_<Tree>("Tree")
.def_readwrite("head",&Tree::head)
;
}
I want to access the head variable from Python, but the message I see is:
No to_python (by-value) converter found for C++ type... | Of course, I find the answer ten minutes after asking the question...here's how it's done:
class_<Tree>("Tree")
.add_property("head",
make_getter(&Tree::head, return_value_policy<reference_existing_object>()),
make_setter(&Tree::head, return_value_policy<reference_existing_object>()))
;
|
2,541,608 | 2,541,699 | Sorting a file with 55K rows and varying Columns | I want to find a programmatic solution using C++.
I have a 900 files each of 27MB size. (just to inform about the enormity ).
Each file has 55K rows and Varying columns. But the header indicates the columns
I want to sort the rows in an order w.r.t to a Column Value.
I wrote the sorting algorithm for this (definitely m... | I'm not sure why your code is crashing, but recursion in that case is only going to make the code less readable. I doubt it's a stack overflow, however, because you're not using much stack space in each call.
C++ already has std::sort, why not use that instead? You could do it like this:
// functor to compare 2 strings... |
2,541,615 | 2,541,937 | error by creating process | hello i want to get startet with programming with WIN32, therefore i wrote a programm that creates a process but in the line of code where i create the process the programm gets an error an dosn't work (abend). i don't know if the code in programm 1 is wrong or the code in the second programm that should be created by ... | Notice the type of the lpCommandLine parameter to CreateProcess -- it is LPTSTR, not LPCTSTR, i.e. it is not const.
This means that CreateProcess reserves the right to actually modify the contents of lpCommandLine. However, you have provided a pointer to a string literal as parameter, and string literals are immutable... |
2,541,663 | 2,541,715 | Operator() as a subscript (C++) | I use operator() as a subscript operator this way:
double CVector::operator() (int i) const
{
if (i >= 0 && i < this->size)
return this->data[i];
else
return 0;
}
double& CVector::operator() (int i)
{
return (this->data[i]);
}
It works when I get values, but I get an error when I try to write assign a value u... | Like I said in my comment, the problem is your flawed design. I make a 100% guarantee on one of two things:
The value you are passing to the assignment function is out of valid range.
The member data is pointing to invalid space in memory.
In either case, I would suggest adding:
#include <cassert>
and adding assert... |
2,541,686 | 2,541,721 | Multiple Instances of Static Singleton | I've recently been working with code that looks like this:
using namespace std;
class Singleton {
public:
static Singleton& getInstance();
int val;
};
Singleton &Singleton::getInstance() {
static Singleton s;
return s;
}
class Test {
public:
Test(Singleton &singleton1);
};
Te... | The first line of Test::Test creates another instance of Singleton (on the stack, your local isn't a reference). You could prevent this by defining the default constructor on Singleton and making it private. As it stands, anybody can create an instance of Singleton.
|
2,541,714 | 5,530,352 | Adding click/double-click events to static group box controls | Having realised my own reasons were way too dubious, I've now gone about this a different way. But I'm still curious...
For reasons of nostalgia, familiarity and laziness, I'm coding a UI with MFC. For dubious reasons (as if those were not enough), I wanted to add a (double-)click event to a group box. Naturally, the g... | I think WM_NCHHITTEST/HT_TRANSPARENT is indeed the key here.
Group boxes are an odd sort of control: while it looks like they contain other controls, they are actually siblings of those controls in the HWND tree. So a groupbox that looks like it contains two buttons is actually a sibling of those buttons - and could co... |
2,541,970 | 2,541,983 | Could someone tell me if my C++ indent style is named? (example given) | I'm learning C++. For me, my programming style is just what looks the best; it doesn't seem to follow the rules of any one particular style. Here's an example
void f(int x){ //no space between close-paren and bracket
if (!x){
cout << "x is non-zero\n";
} //closing bracket indented to the same level as t... | Looks BSD KNF style. see http://en.wikipedia.org/wiki/Indent_style
(note, it's also the same style I prefer :) )
|
2,541,977 | 2,541,998 | C++ string array binary search | string Haystack[] = { "Alabama", "Alaska", "American Samoa", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia",
"Florida", "Georgia", "Guam", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
"Louisiana", "Maine",... | From the SGI docs:
Note that this is not necessarily the information you are interested in! Usually, if you're testing whether an element is present in a range, you'd like to know where it is (if it's present), or where it should be inserted (if it's not present). The functions lower_bound, upper_bound, and equal_rang... |
2,542,089 | 2,542,130 | How can I find the memory available on an SD card on a wince device (C++) | I'm looking for a way (on a pocketPC) to interrogate the size/remaining size of an SD card.
I have to create some files on the SD card and I want to make sure there's enough room before I write to it.
| Look at GetDiskFreeSpaceEx() : http://msdn.microsoft.com/en-us/library/aa912270.aspx
|
2,542,123 | 2,542,140 | Is there any thing hashmap can do but map cannot? | I only know that the difference between hashmap and map is that hashmap is implemented with hash function but map is implemented with tree. Could any body add anything more?
Based on this, is there any thing hashmap can do but map cannot?
|
Hashmaps have average case better performance for access (O(1)), but worse worst case performance (O(n)). Maps are always O(lg(n)).
Maps are ordered by their key, hashmaps are not.
Hashmaps generally use more memory than maps.
Maps typically allow for faster iteration.
Good hash functions are harder to write than good... |
2,542,273 | 2,542,415 | c++ g++ llvm-clang compiler profiling | Note, my question is not: how do I tell my compiler to compile with profiling on.
I want to profile my compiles process. For each file, I'd like to know how much time is spent on each line of the program.
I'm working on a project, some files have huge compile times, I'm trying to figure out why.
Is there anyway to do t... | Try these command line options with g++
-v -ftime-report
That should give you more information on the compiling process. The culprit is usually templates though.
|
2,542,299 | 2,542,543 | Insight into how things get printed onto the screen (cout,printf) and origin of really complex stuff that I can't seem to find on textbooks | I've always wondered this, and still haven't found the answer. Whenever we use "cout" or "printf" how exactly is that printed on the screen?. How does the text come out as it does...(probably quite a vague question here, ill work with whatever you give me.). So basically how are those functions made?..is it assembly?, ... | Here's one scenario, with abbreviations:
printf or cout put characters into a buffer in the user program's address space.
Eventually the buffer fills, or perhaps printf asks for the buffer to be emptied early. Either way, the I/O library calls the operating system, which copies the contents of the buffer to its own s... |
2,542,343 | 2,542,360 | Mutual class instances in C++ | What is the issue with this code?
Here we have two files: classA.h and classB.h
classA.h:
#ifndef _class_a_h_
#define _class_a_h_
#include "classB.h"
class B; //????
class A
{
public:
A() {
ptr_b = new B(); //????
}
virtual ~A() {
if(ptr_b) delete ptr_b; //????
nu... | You cannot create instances of an incomplete type (the compiler doesn't know anything about the class!)
You need to move the definitions of your functions (the constructor of A and B) into a C++ file that can include both headers (or into several C++ files, if you follow the convention that you have one class per file)... |
2,542,349 | 2,542,444 | Static functions vs const functions | I'm looking at a member function
int funct(int x) const;
And I'm wondering if
static int funct(int x);
would be better.
If a member function doesn't use any of the member variables should it be static? Are there any things that would discourage this?
| Assuming this is C++, a function declared as const indicates that it does not intend to change data members on the instance on which it is called, i.e., the this pointer. Since there are ways to evade this, it is not a guarantee, merely a declaration.
A static function does not operate on a specific instance and thus d... |
2,542,400 | 2,542,454 | What Gotchas When Learning C++, If I came from PHP/Java? | I need to learn C++ in order to learn building Nokia WRT and or maemo application.
I need to know what gotchas and what aspect of C++ that I need/have to learn or focus more.
One thing I got in my mind is that C++ doesn't have garbage collector. Therefor, I need to focus on variable type. But, is there any others that ... | Main gotcha is to try to envisage C++ in terms of how it differs from PHP or Java.
Sorry, it just doesn't work like that. C++ differs from those languages in almost every important respect beyond the syntax for arithmetic. Sometimes the differences are subtle. You need to learn it fresh, and not think that something th... |
2,542,447 | 2,543,107 | linking error in Visual c++ when trying to inline functions | When trying to inline a function in Visual C++ (2008 express), I got a linking error, after a close inspection of the code, what I discovered is that the function I am trying to inline throws an exception... if I remove the exception throwing, the linking error goes away, can someone explain why it is the case?
int com... | You'll have to place your definition in the header file.
An inline member function can be defined in two ways:
Define the member function in the class body itself.
Declare the member function just like a normal member function inside the class but when you define the inline member function, prepend the member function... |
2,542,451 | 2,542,481 | Can I pass a child class to a reference of a parent class? | I have a class A which takes a reference of B in its constructor.
class A {
public:
A(B& b);
}
And I have a class SubB which is a child class of B:
class SubB : public B {
//omitted...
}
In my code, I create a SubB and pass it to A:
SubB subB;
A a(subB);
But I get this compile Error:
error: ... | The posted code looks correct though declaration of class B is missing. Post more complete snippet - you problem is likely in misplacing include files and class declarations.
|
2,542,460 | 2,542,522 | Is there a nice Unix command for dumping the text representation of a binary file? | I got some binary files containing integers. Is there some nice Unix command, that will allow me to dump it to a terminal without offset information, etc.?
Something like:
double int[4];
while (fread(tmp, sizeof(int), 4, stdin))
for(int i = 0; i < 4; i++)
printf("%d\t",tmp[i]);
It seems that hexdump and od... | To solve this kind of problem using standard Unix tools, you typically pipe a bunch together:
od -v -t d4 ~/.profile | awk '{$1 = ""; print}' | fmt -1 | sed 's/^ *//'
The od prints every 32-bit word in decimal, with preceding offsets. The awk comment removes the offsets. The fmt command forces one integer per line. ... |
2,542,483 | 2,557,466 | can i use multiple PCH files in 1 project? | I want to use the PCH file to speed up the build, so i store the PCH file in a separate folder and reuse it when build the project later.
but I have some #import *.dll in my stdafx.h. so if something changed in the *.dll, the PCH file need be recreated.
my question is whether I can use multiple PCH files in 1 project, ... | No, you can only include one pch file per cl.exe invocation.
It's a bummer but that's the way it is.
|
2,542,507 | 2,542,539 | Best way to do powerOf(int x, int n)? | So given x, and power, n, solve for X^n.
There's the easy way that's O(n)...
I can get it down to O(n/2), by doing
numSquares = n/2;
numOnes = n%2;
return (numSquares * x * x + numOnes * x);
Now there's a O(log(n)) solution, does anyone know how to do it? It can be done recursively.
| Well, you know that xa+b = xa xb so...
int pow(int x, unsigned int y)
{
if (y == 0) return 1;
if (y == 1) return x;
int a = y / 2;
int xa = pow(x, a);
if (a + a == y) // y even
return xa * xa;
else
return xa * xa * x;
}
|
2,542,545 | 2,548,024 | Configuring a library to be included with C++ test | I would like to utilize the UnitTest++ library in a testing file. However, I am having some difficulty getting the library to be included at compile time. So here is my current directory structure:
tests/
UnitTests++/
libUnitTest++.a
src/
UnitTests++.h
unit/
test.cpp
I have just used the UnitTest... | I was able to build it in the following manner
gcc -L../UnitTest++/ -I../UnitTest++/src/ test.cpp -lUnitTest++ -lstdc++
or
g++ -L../UnitTest++/ -I../UnitTest++/src/ test.cpp -lUnitTest++
that links to libstdc++ automatically.
GCC documentation says:
-llibrary
-l library
Search the library named library when linking... |
2,542,621 | 2,542,638 | Is there a way to identify version of c/c++ library? | For example, how to get the version of /usr/lib/libz.a? It will be great if other useful information such as compiler/arch etc. can be fetched.
The reason I want to know this is that gcc always say it ignored the libz I offered in command line when I compile my program and linked with specific versioned libz. gcc think... | C libraries do not have on their own a versioning system. At best, there is a symbol in the library that tells it.
|
2,542,890 | 2,542,904 | return char1 + char2? Isn't it possible? | I'm trying to return a string from a function. Which basically adds some chars together and return the string representation.
string toString() {
char c1, c2, c3;
// some code here
return c1 + c2; // Error: invalid conversion from `char' to `const char*'
}
it is possible to return boolean values like return c... | No, you can't do that because adding two char's together doesn't give you a string. It gives you another char; in this case 'a'+'b' actually gives you '├' (on Windows with the standard CP_ACP code page). Char is an ordinal type, like integers and the compiler only knows how to add them in the most basic of ways. Str... |
2,543,057 | 2,543,115 | getline() returns empty line in Eclipse but working properly in Dev C++ | Here is my code:
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main() {
string line;
ifstream inputFile;
inputFile.open("input.txt");
do {
getline(inputFile, line);
cout << line << endl;
} while (line != "0");
return 0;
}
input.txt conte... | Since you are on windows try:
} while (line != "0\r");
The last line is stored as "0\r\n". The \n is used as the line delimiter by getline so the actual line read will be "0\r"
or
you can convert the dos format file to UNIX format using command
dos2unix input.txt
Now your original program should work. The command wil... |
2,543,188 | 2,543,455 | Which is the fastest way to scan files in FAT32 disk? | I want to scan FAT32 disk (I just need file path and file name) as soon as possible in C++,
Scan every files on FAT32 disk.
Is there any API to do this?
| Check this thread: How can I quickly enumerate directories on Win32?
It actually describes FindFirstFile/FindNextFile, but if you need it faster you should go Kernel.
The index solution described in the thread will however not work for FAT32 systems - credit MSalters
|
2,543,201 | 2,543,216 | Why does `&*(&*d)` return address of "c" instead of address of "b"? | I made some code, for understanding the concept/basic of pointer:
int a=1;
int *b=&a;
int **c = &b;
int ***d = &c;
cout << &*(&*d) << endl;
Why does &*(&*d) return address of "c" instead of address of "b"?
I've also tried code like &*(&*(&*(&*(&*d)))), but it keep return address of "c"
| Because the &* cancels each other out. * dereference d which gives the value of c. And then & gives the address of c, or the value of d.
|
2,543,331 | 2,543,404 | What does 'const' do in operator() overloading? | I have a code base, in which for Matrix class, these two definitions are there for () operator:
template <class T> T& Matrix<T>::operator() (unsigned row, unsigned col)
{
......
}
template <class T> T Matrix<T>::operator() (unsigned row, unsigned col) const
{
......
}
One thing I understand is that the secon... | Which function is called depends on whether the instance is const or not. The first version allows you to modify the instance:
Matrix<int> matrix;
matrix(0, 0) = 10;
The const overload allows read-only access if you have a const instance (reference) of Matrix:
void foo(const Matrix<int>& m)
{
int i = m(0, 0);... |
2,543,394 | 2,543,560 | Determining actual args an Excel UDF was called with | I'm adding a user defined function to Excel with varargs-based signature in C++:
LPXLOPER MyFunction(...);
When Excel calls MyFunction, it passes it 30 arguments regardless of how many the user entered in the sheet. The extraneous ones are blank strings.
MyFunction, however, is designed to accept empty string argument... | I've found a simple way to get hold of the caller cell.
Use excelApp->get_Caller();
|
2,543,751 | 2,543,847 | Segfault in a matrix code using new | I created a simple class in C++ which has a private dynamic array. In the constructor I initialize the array using new and in the destructor I free it using delete.
When I instantiate the class using Class a = Class(..); it works as expected, however it seems I cannot instantiate it using the new operator (Like Class *... | Replace i*n + j by i*m + j.
and replace a[n][m] by a[i][j]
|
2,543,813 | 2,543,843 | ld reports missing symbols, but symbols seem to exist | I'm trying to link my mac application to the wonderful libancillary library. However, I have changed the library build script to create a shared library. I can inspect the symbols in this library using nm libancillary.dylib - the result is:
libancillary.dylib(single module):
U ___sF
U __keymgr_get_and... | Those symbols are unmangled C symbols. As you have tagged this as C++, I assume you are compiling with C++. If you do that you may need to wrap your libraries header files in an extern block in your code:
extern "C" {
#include "library.h"
}
where library.h is the name of the library's header file(s), to prevent them ... |
2,543,996 | 2,544,182 | C++ wrapper for posix and linux specific functions | Do you know about any good library wrapping posix and linux functions and structures ( eg. sockets or file descriptors ) into C++ classes? For example I'm thinking about a base FileDescriptor class and some inheriting classes ( unix sockets etc ) with methods like write, read or even some syscalls ( sendfile, splice ) ... | Try Common C++. I haven't used it myself, but it supports the things you've mentioned.
|
2,544,398 | 2,551,738 | CHtmlView class and focus | I have an SDI application written in MFC. The frame is divided into 1 row and 2 columns using a splitter window. Below are details of Row and Column (R0C0 means Row#0 and Col#0)
R0C0 view is a CFormView with multiple input controls like text box, combo box etc.
R0C1 view is a CHtmlView that contains HTML content rela... | Try to overload CHtmlView::OnTranslateAccelerator. I have successfully used this trick to disable refresh with F5 key. Derive your own class from CHtmlView and overload
virtual HRESULT OnTranslateAccelerator(LPMSG lpMsg, const GUID* pguidCmdGroup, DWORD nCmdID);
like this:
HRESULT CMyHtmlView::OnTranslateAccelerator... |
2,544,782 | 3,407,557 | Doxygen groups and modules index | I am creating a Doxygen document for my project. Recently, I have grouped related classes using \addtogroup tag. After this, I have got a module tab in my documentation. It shows all modules. I want to add some description right below module name below the module name on the same page. How can I do it using Doxygen ?
H... | You have to write a dedicated .h file which contains only comments.
For each group you define a comment like this:
/** @defgroup FooGroup
*
* This module does yada yada yada
*
*/
Then you assign definition to the group (even on different files) like this:
/** @addtogroup FooGroup */
/*@{*/
/** Summon a goat
*
*... |
2,544,805 | 2,544,848 | VS 2008 Compiler option for flagging uninitialized variables | Is there a compiler option in VS 2008 (C++) to expose uninitialized variables? I'm trying to debug a problem where the "release" build of a DLL does not work but the "debug" build of the DLL does work.
| iirc, setting warning level to 4 will help with this
|
2,544,809 | 2,544,847 | bitwise OR on strings | How can i do a Bitwise OR on strings?
A:
10001
01010
------
11011
Why on strings?
The Bits can have length of 40-50.Maybe this could be problematic on int ?
Any Ideas ?
| I would say std::bitset is more than enough for your situation, but for more flexibility you can use boost::dynamic_bitset. Here is an example on std::bitset:
const size_t N = 64;
string a_str = "10001", b_str = "01010";
bitset<N> a(a_str), b(b_str);
bitset<N> c = a | b;
cout << c;
|
2,544,852 | 2,544,872 | Using the same variable across multiple files in C++ | In the process of changing some code, I have spilt some functions into multiple files. I have the files controls.cpp and display.cpp and I would like to be able to have access to the same set of variables in both files. I don't mind where they are initialized or declared, as long as the functions in both files can use ... | Define the variable in one file like:
type var_name;
And declare it global in the other file like:
extern type var_name;
|
2,544,868 | 2,550,359 | What happens to an ActiveX control (COleControl) after the call to OnDestroy()? | I have an ActiveX control written in C++ that runs in Internet Explorer 8. Most of the time (approx 90%) when the tab or browser containing the control is closed, there is an access violation like this:
The thread 'Win32 Thread' (0x1bf0) has exited with code 0 (0x0).
Unhandled exception at 0x77b3b9fd in iexplore.exe: 0... | As I understand, there is no strictly event lifecycle for an ActiveX, it depends on host side. If your control is used with some AJAX framework, for example, after OnDestroy() can be called OnCreate() without calling destructor. So, make sure you don’t have uninitialize actions inside OnDestroy() handler.
You can load... |
2,544,896 | 2,544,910 | Confused about type conversion in C++ | In C++, the following lines have me confused:
int temp = (int)(0×00);
int temp = (0×00int);
What is the difference between those 2 lines?
| Both are invalid because you are using × instead of x:
test.cpp:6: error: stray '\215' in program
test.cpp:6: error: expected primary-expression before "int"
test.cpp:6: error: expected `)' before "int"
But even fixing that, the second still isn't valid C++ because you can't write 0x00int:
test.cpp:6:13: invalid suffi... |
2,544,928 | 2,545,261 | How to extract channel POD-type from a boost::gil homogeneous pixel type? | I have a class templated on <PIXEL>, assumed to be one of boost::gil's pixel types (for now, only either gray8_pixel_t or gray16_pixel_t, and I only expect to support homogeneous pixel types e.g rgb8_pixel_t in future).
The class needs to get hold of unsigned char or unsigned short as appropriate to the pixel type; I a... | Aha.. this seems to do the trick:
typename boost::gil::channel_type<PIXEL>::type
|
2,544,977 | 2,545,193 | Resize QTextEdit in a QWidget while it is being resized the QWidget | How to make QTextEdit to be resized in a QWidget while the QWidget is being resized?
Should I overload resizeEvent function for the QWidget?
| No, you should set the sizePolicy property for your QTextEdit object.
|
2,545,101 | 2,545,165 | convert bitset to string? | What is wrong with this code ?
set<string> nk ;
bitset<3> bs1(string("100"));
nk.insert(bs1.to_string());
error: no matching function for call to `std::bitset<3u>::to_string()'
why?!
UPDATE :
Thansk , this works . But why does it work ? :D
| While checking Space_COwbOy's answer, I found another page that shows that to_string is a template function (with parameters similar to std::basic_string). I haven't tried this, so just check it out.
|
2,545,343 | 2,545,388 | Setting pointers to structs | I have the following struct:
struct Datastore_T
{
Partition_Datastores_T cmtDatastores; // bytes 0 to 499
Partition_Datastores_T cdhDatastores; // bytes 500 to 999
Partition_Datastores_T gncDatastores; // bytes 1000 to 1499
Partition_Datastores_T inpDatastores; // bytes 1500 1999
Partition_Datastores_T outDat... | I don't know why you are getting an address of zero, but I would guess the code you don't show has something to do with it. Some other points:
Consider using an array of Partition_Datastores_T inside your struct
Do not use magic numbers for struct sizes, you want sizeof(Datastore_T )
There is no need for the intermedi... |
2,545,352 | 2,545,408 | Hide console window in Windows Forms application | I took over a Visual C++ project in Visual Studio 2005 from a colleague. It is a Windows Forms project (I assume). But when I start it, besides the Windows Form it also shows a console window. How do I get rid of this console window? I think it must be a project setting but I don't find it.
Any help is appreciated ...
| In the project properties for all configurations (Project | Properties, choose Configuration 'All Configurations', locate Config Properties -> Linker -> System), change the SubSystem from Console to Windows.
|
2,545,577 | 2,563,949 | QSplitter becoming undistinguishable between QWidget and QTabWidget | I am puting a QWidget and a QTabWidget next to each other in one horisontal splitter. And the splitter loses it's shape, you can know that there is a splitter only by hovering mouse on it. How to make it visible?
Thanks.
| Since the QSplitterHandle (which is what most people think of as the 'splitter') is derived from QWidget, you can add other widgets to it. Here is what I have done to solve this exact problem in the past:
// Now add the line to the splitter handle
// Note: index 0 handle is always hidden, index 1 is between the two wi... |
2,545,635 | 2,545,657 | Basic Boost Regex question | I'm trying to write some c++ code that tests if a string is in a particular format. In this program there is a height followed by some decimal numbers:
for example
"height 123.45" or "height 12" would return true but
"SomeOtherString 123.45" would return false.
My first attempt at this was to write the following:
strin... | Drop the trailing slash and it should work. Probably left over from a JavaScript regex? In JavaScript, regexes are often delimited by slashes; in C++, they are simply strings. If you keep the slash where it is, the regex engine is instructed to match a slash after the end of the string ($), which always fails, of cours... |
2,545,681 | 2,546,690 | Way to exclude a char from a word selection | I'm extending a QPlainTextEdit.
When I double click on a word containing a pipe char ex : {"foo"|upper|reverse}
the whole text is surrounded.
I'd like to exclude the pipe char "|" from the selection and don't know what to do
Is there a way to change the behavior of QTextCursor::WordUnderCursor?
I'd like that char to ac... | Currently there is no official way to change the way a text edit finds the word boundaries. See http://bugreports.qt-project.org/browse/QTBUG-150.
You may use their private API to change the behaviour of QTextEngine::atWordSeparator. This way is not recommanded by Qt. The pipe is recognized as word separator in 4.6 but... |
2,545,720 | 2,545,733 | error: default argument given for parameter 1 | I'm getting this error message with the code below:
class Money {
public:
Money(float amount, int moneyType);
string asString(bool shortVersion=true);
private:
float amount;
int moneyType;
};
First I thought that default parameters are not allowed as a first parameter in C++ but it is allowed.
| You are probably redefining the default parameter in the implementation of the function. It should only be defined in the function declaration.
//bad (this won't compile)
string Money::asString(bool shortVersion=true){
}
//good (The default parameter is commented out, but you can remove it totally)
string Money::asStr... |
2,545,731 | 2,545,757 | problem understanding templates in c++ | Template code is not compiled until the template function is used. But where does it save the compiled code, is it saved in the object file from which used the template function in the first place?
For example,
main.cpp is calling a template function from the file test.h, the compiler generates an object file main.o,
... | It's totally compiler implementation dependant. Most compilers will generate code around, inline or in cpp-like files and then compile with that. Sometimes, with optimization setup, some compilers will even reuse the same code instead of recreate it for each cpp.
So you have to see your compiler's doc for more details... |
2,545,858 | 2,545,920 | C++ Access to SQL Server from Linux | I need to write some data to SQL Server database from Linux in C++.
I found this sqlapi.com
But I think, at first ODBC driver has to be installed and has to work.
I folowed this
adminlife.net/allgemein/mssql-zugriff-unter-debian-etch-mit-unixodbc-und-freetds/
or this
http://b.gil.megiteam.pl/2009/11/linux-odbc-to-mssql... | Here are the links I bookmarked concerning that topic, hope it can help you:
ODBC Tutorial
FreeTDS
Connection strings
How to configure ODBC - This one was really useful.
It was some time ago, but basically what I remember is:
You have to create an entry for the particular MSSQL driver you have in a file named /etc/od... |
2,546,212 | 2,546,354 | ATLComTime.h is part of what redistributable? | I added functionality to a code base someone else wrote and while the "Not using ATL" flag was set in VS2005 I see that there is #include <ATLComTime.h> in one of the files. I have only sent the C-Runtime library (see here) redistributable. The client can not get the code to worktheir machines. They receive a "DLL e... | Configure the project to link statically with ATL (Project | Properties -> Config Properties -> General -> Use of ATL) executable, or distribute atl.dll with your application.
|
2,546,328 | 2,546,612 | How to call an programmatically generated event for wxRadioButton in wxWidgets? | I am trying to programmatically change a value of a wxRadioButton in a way the user would do it. A value change doesn't call the event corresponded to the button, and it make sense since the documentation says it clearly:
wxRadioButton::SetValue
void SetValue(const bool value)
Sets the radio button to selected or desel... | You can use AddPendingEvent or ProcessEvent (handle immediately).
bttn->SetValue(true);
wxCommandEvent ev(wxEVT_COMMAND_RADIOBUTTON_SELECTED, id_button);
bttn->GetEventHandler()->ProcessEvent(ev);
It should also be possible to use wxControl::Command, but it seems to me that SetValue should be called after that(?).
|
2,546,331 | 2,546,398 | Difference between debug and release when viewed in debugger | I'm viewing variables using the debugger. In debug builds everything in the code below appears as I expect it to, but when I switch to release builds I'm getting strange results. Why?
#include <iostream>
void say_hello(int argc, char* argv[])//In release mode argc has different values from 124353625 to 36369852 when v... | Since you're not using those parameters in your program, you must be trying to observe their values in the debugger. But, again since you're not using them in your program, the compiler is free to do whatever it wants with their values. It may remove them entirely, leaving the debugger with nothing but gibberish to dis... |
2,546,706 | 2,546,716 | Pointers in C# to make int array? | The following C++ program compiles and runs as expected:
#include <stdio.h>
int main(int argc, char* argv[])
{
int* test = new int[10];
for (int i = 0; i < 10; i++)
test[i] = i * 10;
printf("%d \n", test[5]); // 50
printf("%d \n", 5[test]); // 50
return getchar();
}
The closest C# s... | C# is not C++ - don't expect the same things to work in C# that worked in C++. It's a different language, with some inspiration in the syntax.
In C++, array access is a short hand for pointer manipulation. That's why the following are the same:
test[5]
*(test+5)
*(5+test)
5[test]
However, this is not true in C#. 5[... |
2,546,757 | 2,546,842 | Executing MSYS from cmd.exe with arguments | I am trying to learn the wxWidgets library, using MinGW and msys to compile the code. So far so good, but I can not find a way to send a command to MSYS through CMD.exe.
I use Sublime Text to edit files, and it has an option to run makefiles. I want my makefiles to be able to open an instance of MSYS and send the g++ c... | You probably want to set the shell that gmake uses to execute the commands that make up the makefile. I assume that MSYS comes with bash or even plain sh, which should do the job.
|
2,547,043 | 2,547,088 | Passing multiple vectors to function by reference (using structure) | Can someone tell me the correct way of passing multiple vectors to a function that can take only a single argument? (specifically for pthread_create (..) function)
I tried the following but it does not seem to work :-(
First, I created the following structure
struct ip2
{
void* obj;
int dim;
int n_s;
... | nrsv is a vector<int>*, right? So you need to do end = index + (*nrsv)[k]; (dereference it).
|
2,547,531 | 2,547,725 | STL algorithms and concurrent programming | Can any of STL algorithms/container operations like std::fill, std::transform be executed in parallel if I enable OpenMP for my compiler? I am working with MSVC 2008 at the moment.
Or maybe there are other ways to make it concurrent?
Thanks.
| There are a number of projects that aim at having parallel STL type libraries:
OpenMP Multi-Threaded Template Library
libstdc++ parallel
HPC++ Parallel Standard Template Library
Parallel Patterns Library (shamelessly borrowed from AshleysBrain's answer)
|
2,547,630 | 2,547,667 | hiding exectables using ADS (Alternate data streams) | i hear that NTFS alternate data streams can be used to hide running executabes.
eg
supporse i have an exe called hiddenProgram.exe on windows xp,using cmd.exe or system(char*) calls in c,
type hiddenProgram.exe > c:\windows\system32\svchost.exe:hiddenProgram.exe
start c:\windows\system32\svchost.exe:hiddenProgram.exe
... | In NTFS you can have one or more streams associated with a file. There is always an unamed stream that everyone knows about, but you can also have named streams which are refered to as Alternate Data Streams (ADS).
starts svchost and at the same time
hiddenProgram.exe
No it only starts just the program contained i... |
2,547,635 | 2,547,699 | Is size_t only in C++ standard or C standard as well? | Is size_t only in C++ standard or C standard as well?
I cannot find a C header in the "/usr/include" tree that defines size_t.
If it is not in the C std, is GCC just doing some magic to make things work?
Thanks,
Chenz
| From C99 draft:
7.17 Common definitions <stddef.h>
The following types and macros are defined in the standard header <stddef.h>. Some
are also defined in other headers, as noted in their respective subclauses.
The types are [-snip-]
size_t
which is the unsigned integer type of the result of the sizeof operator; [-sni... |
2,547,686 | 2,547,746 | Decimal type in Qt (C++) | What is the correct type to use in Qt development (or C++ in general) for decimal arithmetic, i.e. the equivalent of System.Decimal struct in .Net?
Does Qt provide a built-in struct? (I can't find it in the docs, but maybe don't know where to look.)
Is there a "standard" C++ library to use?
|
What is the correct type to use in Qt
development (or C++ in general) for
decimal arithmetic, i.e. the
equivalent of System.Decimal struct in
.Net?
Neither C++ standard library nor Qt has any data type equivalent to System.Decimal in .NET.
Does Qt provide a built-in struct? (I
can't find it in the docs, bu... |
2,547,789 | 2,547,878 | Shift Operators in C++ |
If the value after the shift operator
is greater than the number of bits in
the left-hand operand, the result is
undefined. If the left-hand operand is
unsigned, the right shift is a logical
shift so the upper bits will be filled
with zeros. If the left-hand operand
is signed, the right shift may or may
... | I'm assuming you know what it means by shifting. Lets say you're dealing with a 8-bit chars
unsigned char c;
c >> 9;
c >> 4;
signed char c;
c >> 4;
The first shift, the compiler is free to do whatever it wants, because 9 > 8 [the number of bits in a char]. Undefined behavior means all bets are off, there is no way o... |
2,547,792 | 2,547,914 | How do interpreters written in C and C++ bind identifiers to C(++) functions | I'm talking about C and/or C++ here as this are the only languages I know used for interpreters where the following could be a problem:
If we have an interpreted language X how can a library written for it add functions to the language which can then be called from within programs written in the language?
PHP example:
... | Actually scripting languages do something like what you mentioned.
They wrap functions and they register that functions to the interpreter engine.
Lua sample:
static int io_read (lua_State *L) {
return g_read(L, getiofile(L, IO_INPUT), 1);
}
static int f_read (lua_State *L) {
return g_read(L, tofile(L), 2);
}
...... |
2,547,988 | 2,581,199 | Boost Unit testing memory reuse causing tests that should fail to pass | We have started using the boost unit testing library for a large existing code base, and I have run into some trouble with unit tests incorrectly passing, seemingly due to the reuse of memory on the stack.
Here is my situation:
BOOST_AUTO_TEST_CASE(test_select_base_instantiation_default)
{
SelectBase selectBase(... | I ended up writing a function to set the object to an invalid state after each test case:
void unsetSelectBase(SelectBase selectBase)
{
selectBase.setSelectType(true);
selectBase.getTypeName(_T("InvalidName"));
selectBase.getEntityType(42);
selectBase.getDataPos(2718);
}
BOOST_AUTO_TEST_CASE(test_sele... |
2,548,075 | 2,548,602 | C++ string template library | I want simple C++ string based template library to replace strings at runtime.
For example, I will use
string template = "My name is {{name}}";
At runtime, I want the name to be changed based on actual one.
I found one example, www.stringtemplate.org but I little scared when its talks about antlr etc.
| Update: The project has moved to Github and renamed into CTemplate: https://github.com/OlafvdSpek/ctemplate
From the new project page:
was originally called Google Templates, due to its origin as the template system used for Google search result pages. Now it has a more general name matching its community-owned natur... |
2,548,130 | 2,549,263 | How to store wxImage into database, using C++? | I have some wxImages and I would like to store them into a BLOB (Binary Large OBject) field in a MySQL database.
There are no methods in wxImage nor wxBitmap for obtaining the binary data as an array of unsigned char so I can load into the database.
My current workaround is to write the image to a temporary file, the... | wxWidgets doesn't provide any API to the data from wxBitmap (because it's platform-dependent) but wxImage uses a well-defined (and very simple) format which you can access using its GetData() method as mentioned above. Just notice that you may need to use GetAlpha() as well if your images have alpha channel.
However th... |
2,548,249 | 2,548,351 | Boost Regex throwing an error | I have the following error when I try to compile my code in g+ compiler using eclipse
In function `ZSt19__iterator_categoryIPKSsENSt15iterator_traitsIT_E17iterator_categoryERKS3_':
C:/Program Files (x86)/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algobase.h:(.text$_ZN5boost11basic_regexI... | It appears that you're not linking to the correct library. Most Boost libraries are header-only, so you don't need to do anything about them at link time. Boost::regex, however, is one of the few that requires that you link with a library along with giving the compiler the proper headers.
After you fix that, you'll wan... |
2,548,282 | 2,548,374 | Decimal to binary (and vice-versa) | Can anybody give an example of c++ code that can easily convert a decimal value to binary and a binary value to decimal please?
| Well, your question is really vague, so this answer is the same.
string DecToBin(int number)
{
if ( number == 0 ) return "0";
if ( number == 1 ) return "1";
if ( number % 2 == 0 )
return DecToBin(number / 2) + "0";
else
return DecToBin(number / 2) + "1";
}
int BinToDec(string number)
{... |
2,548,488 | 2,548,525 | Analyze log files from many languages using a single tool. And recommendations of logging frameworks | We have a system build on lots of languages. The ones we are interested in logging, in order of priority, are:
C/C++
PHP
C#
Bash
Java
Wish list:
If it is possible, we would like logging to be achieved from the above languages in such a way that we may use a single log viewing tool for all of them. Ideally they would... | If you are using linux, syslog is great! The project I am working on right now uses syslog for most of our logging; everything goes to the same place (/var/log/messages) and you are able to log from many different tools all to the same log file. Apparently you can also use syslog to log to a remote server.
Otherwise if... |
2,548,510 | 2,548,858 | passing values between 2 different c++ files in same project | noob question right here. How do you pass values between 2 different cpp files in the same project? Do you make objects? if yes, how does the other cpp file see it?
some enlightment pls..
EDIT: some clarifications. I'm trying to interface direct input with a program (of which I have the plugins sdk). I'm trying to inte... | In all but few cases it's a bad idea to share data among compilation units. A compilation unit, just to get you up to speed with the C++ terminology, usually effectively refers to an implementation file (with extension .cpp, or .cc etc.). The way we have the various compilation units "communicate" with each other is wi... |
2,548,555 | 2,548,586 | dot asterisk operator in c++ | is there, and if, what it does?
.*
| Yes, there is. It's the pointer-to-member operator for use with pointer-to-member types.
E.g.
struct A
{
int a;
int b;
};
int main()
{
A obj;
int A::* ptr_to_memb = &A::b;
obj.*ptr_to_memb = 5;
ptr_to_memb = &A::a;
obj.*ptr_to_memb = 7;
// Both members of obj are now assigned
}
Her... |
2,548,683 | 2,551,908 | C++ programming for clusters and HPC | I need to write a scientific application in C++ doing a lot of computations and using a lot of memory. I have part of the job but due to high requirements in terms of resources I was thinking to start moving to OpenMPI.
Before doing that I have a simple curiosity: If I understood the principle of OpenMPI correctly it ... | Currently there is no C++ library or utility that will allow you to automatically parallelize your code across a cluster of machines. Granted that there are a lot of ways to achieve distributed computing with other approaches, you really want to be optimizing your application to use message passing or distributed share... |
2,548,887 | 2,549,144 | 0 not a valid FILE* when provided as a template argument | The following code
#include <stdio.h>
template <typename T, T v> class Tem
{
T t;
Tem()
{
t = v;
}
};
typedef Tem<FILE*,NULL> TemFile;
when compiled in a .mm file (Objective C++) by Xcode on MacOS X, throws the following error:
error: could not convert template argument '0' to 'FILE*'.
What's ... | According to the standard, you are out of luck. There is no way to initialize a pointer argument to anything besides the address-of a global. §14.3.2/1:
A template-argument for a non-type,
non-template template-parameter shall
be one of:
an integral constant-expression of integral or enumeration type; or
the name... |
2,548,918 | 2,549,103 | Is there any Graph Builder for GStreamer? | Is there any Graph Builder for GStreamer? So to say you build graph you get code
| gst-editor seems to be something like what you are looking for. It doesn't appear to support generating C++ code, but what it does support is saving XML that can be loaded into your program in the same way that libglade allows you to load Glade GUIs. It looks very intuitive and low-nonsense, judging by the screen shots... |
2,549,015 | 2,549,323 | Finding a MIME type for a file on windows | Is there a way to get a file's MIME type using some system call on Windows? I'm writing an IIS extension in C++, so it must be callable from C++, and I do have access to IIS if there is some functionality exposed. Obviously, IIS itself must be able to do this, but my googling has been unable to find out how. I did f... | HKEY_CLASSES_ROOT\\.<ext>\Content Type (where "ext" is the file extension) will normally hold the MIME type.
|
2,549,019 | 8,125,118 | How to avoid namespace content indentation in vim? | How to set vim to not indent namespace content in C++?
namespace < identifier >
{
< statement_list > // Unwanted indentation
}
Surprisingly, 'cinoptions' doesn't provide a way to edit namespace content indentation.
| Not sure when it was introduced but my installed version of vim, v7.3.353 has a cino option that handles cpp namespace explicitly. I am currently using the example value:
cino=N-s
and as per :help cinoptions-values
NN Indent inside C++ namespace N characters extra compared to a
normal block. (default 0).
cino= ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.