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 |
|---|---|---|---|---|
7,324,935 | 7,324,953 | Problem with fopen and the windows console | I'm having a very strange problem. I'm using Visual Studio 2010 Ultimate on Windows 7 x64. I have this simple code:
#include <stdio.h>
int main()
{
fclose( fopen("hakuna", "w") );
return 0;
}
It works very well when I compile it. When I go to the debug folder and double click on the exe it creates the file. B... | It's being created at your default directory - or wherever your cmdline active directory is.
For example, the cmdline will look like something like this.
C:\Users\Akari>
That's the directory where the file is being made.
|
7,325,245 | 7,325,285 | Is there an output stream besides cout in C++? | My C++ book gives the following example regarding cout:
cout << "literals" << "to be" << "printed" ;
Then, it goes on to say:
The statements starts with the name of the output stream, cout
This seems to imply that there are other streams. Are there other output streams besides cout in C++? What are they?
| Some examples:
The std::cerr value from <iostream> - standard error stream
The std::fstream type from <fstream> - file input and file output streams
The std::stringstream type from <sstream> - string streams
|
7,325,399 | 7,333,530 | Can "construct on first use" idiom fail under any circumstances? | I'm building my program (tests actually) using some static library.
This library contains one file inside which I have functions like that:
string& GetString() {
static string strFilename;
return strFilename;
}
void PrintToScreen() {
printf("String: %s\n", GetString().c_str())
}
Then in my main.cpp (outsi... | Actually there was one missing think in example. It should look like this:
string& GetString() {
static string strFilename;
return strFilename;
}
extern "C" {
void PrintToScreen() {
printf("String: %s\n", GetString().c_str())
}
}
Strange. Anyway, I refactored it to something like this:
extern "C" {
stri... |
7,325,825 | 7,327,860 | Organize cross-platform C/C++ project | What is the usual/recommended way how to organize a multi-platform (Windows, Linux) C/C++ library project?
How to name function and provide OS-dependent implementations, organize includes etc.? Please, constructive ideas only -- no pointers as "Look at Linux.", ideas strongly welcome.
| I use folders to put the dependent header/source files as this example shows
fs/filesystem.hpp <-- main generic header that is what you include in any project and you can create a #define in there to ensure that a person only includes this one and if they include a sub one below, it will give a compile error pointing t... |
7,325,844 | 7,325,966 | Implementing a multiplier in a statistician class | I am working on a programming assignment for my data structures class and we are working on making a statistician class. One of the functions that we have to have is to be able to take a statistician list (count, sum, min, max and mean) and multiply it by a certain integer. Below is what i have so far for the specific ... | You are trying to create a copy of the class statistician, but scaled by scale. Something like
statistician operator *(double scale, const statistician& s)
{
statistician result(s);
result.total *= scale;
result.tinyest *= scale;
result.largest *= scale;
return result;
}
The member function scaleB... |
7,325,910 | 7,326,804 | Debugging template instantiations | When doing metaprogramming using C++ templates, is there a method that can be used, sort of like a debugger, to step through how the templates are being instantiated and complied? It seems right now, when creating a complicated network of templates, there really isn't a very good way of debugging them other than looki... | These are pretty basic, but they have worked for me in most cases. I'm interested to see what others have to say too.
Apologies for the contrived examples.
Use sandboxes
Starting with small sandboxes to test template code as soon as it starts behaving weird or you are doing something complicated. I am pretty comforta... |
7,325,993 | 7,326,089 | How to duplicate CString functionality | I have an MFC source file that I need to compile under Qt. This file uses MFC/ATL CString. Specifically it uses a CString as an argument to iostream::open(). I have written a CString class that inherits from QString so that I can use most of QStrings' functionality.
My main concern is that I cannot get my CString ... | Define a typecast operator for your CString class as follows:
operator const char*() { return this->toStdString().c_str(); }
|
7,326,123 | 7,326,381 | Convert MAC address std::string into uint64_t | I have a hexadecimal MAC address held in a std::string. What would be the best way to turn that MAC address into an integer-type held in a uint64_t?
I'm aware of stringstream, sprintf, atoi, etc. I've actually written little conversion functions with the first 2 of those, but they seem more sloppy than I would like.
... | uint64_t string_to_mac(std::string const& s) {
unsigned char a[6];
int last = -1;
int rc = sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%n",
a + 0, a + 1, a + 2, a + 3, a + 4, a + 5,
&last);
if(rc != 6 || s.size() != last)
throw std::runtime_error("inva... |
7,326,522 | 7,326,561 | main function stack size | Max function stack size is limited and can be quickly exhausted if we use big stack variables or get careless with recursive functions.
But main's stack isn't really a stack. main is always called exactly once and never recursively. By all means main's stack is static storage allocated at the very beginning and it live... | It's implementation-defined (the language standard doesn't talk about stacks, AFAIK). But typically, main lives on the stack just like any other function.
|
7,326,599 | 7,326,642 | Failing to use a vector iterator, c++ | I'm trying to iterate over a vector holding a pointer to an object of type Student.
The declaration of vector is as follow: static vector<Student*> students;
Anyhow, I am trying to use an iterator in function pickWinners():
vector<Student*>::iterator p1 = students.begin();
vector<Student*>::iterator p2 = p1;
p2++;
As ... | The desired result would be achieved by
(*p1)->print();
In your case, the code parses as *(p1->print());, because operator-> has higher precedence than operator*, see for example, the precedence table on wikipedia
|
7,326,860 | 7,326,893 | Char 2D array in map in C++ | How can I use a 2D char array with a map in C++. I want to do this:
map<char[50][50],int>M;
char brr[50][50];
//some operation here on the array
int aa=1;
if(M.find(brr)==M.end())
{
M[brr]=aa;
aa+=1;
}
what am I doing wrong?
EDIT:
I've just found another way. This way I can achieve what I stated in my ques... | You can't. Arrays can't be assigned to (i.e. you can't do brr = XXX; in your example), and this is a requirement of the key type of a std::map. Also, the key needs to have a strict weak ordering defined on it (i.e. it needs operator< or a comparator function).
You could consider wrapping your array in a class, defini... |
7,327,000 | 7,327,641 | Make an implicit conversion operator preferred over another in C++ | I would like to prefer a certain implicit conversion sequence over another. I have the following (greatly simplified) class and functions:
class Whatever {...}
template <class T>
class ref
{
public:
operator T* ()
{
return object;
}
operator T& ()
{
... | Simple: define void f(const ref<Whatever>&), it will trump the others which require a conversion.
|
7,327,015 | 7,327,047 | About two kinds of singleton pattern in C++ | When I look for informations about the singleton pattern for C++, I always find examples like this:
class Singleton
{
public:
~Singleton() {
}
static Singleton* getInstance()
{
if(instance == NULL) {
instance = new Singleton();
}
r... | http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14
The static initialization order fiasco is a very subtle and commonly
misunderstood aspect of C++. Unfortunately it's very hard to detect —
the errors often occur before main() begins.
In short, suppose you have two static objects x and y which exist in
s... |
7,327,070 | 7,327,114 | String concatenation C++ | Given an arbitrary floating point number, say -0.13, suppose we have an algorithm which calculates a binary string of known length L for this number, one by one, from left to right.
(I need to do this computation for calculating the Morton Key ordering for particles(co-orindates given) which in turn in used in buildin... | Why not do both?
std::string myStr(L);
for(i = 0; i < L; ++i)
{
// calculation of ch[i]
myStr[i] = ch;
}
This creates a std::string with a given size. You then just set each character. This will only work if you can know the size beforehand exactly.
Alternatively, if you want something that is safe, even if y... |
7,327,250 | 7,327,366 | Segmentation fault when calling "new" in c++? | I got segfault when trying to call "new" to create a pointer and push it into a vector. The code that I push the element in the vector is:
queue->push_back(new Box(gen_id, Interval(x_mid, x_end), Interval(y_mid-y_halfwidth, y_mid+y_halfwidth)));
Basically Box is a Class and the constructor just take 3 arguments, gener... | Assuming it really is new generating the segfault, the most common cause would be a corrupted heap, typically a result of overwriting memory you don't own and/or a double delete.
Valgrind will be your friend if you can run on a Linux system.
|
7,327,381 | 7,327,592 | Overloading >> Error C++ | Whenever I try to compile my program, I get a strange error. I have tried to look it up, and trying different methods of overloading it, but I still get errors.
istream& operator >> ( istream& in, MysteryCard& theMysteryCard )
{
int value;
in >> value;
theMysteryCard.change(value);
return in;
}
All of my varia... | It appears to me that you're missing an include. Make sure you have #include <istream> and that you have either a using declaration for std::istream or a using directive for namespace std.
|
7,327,581 | 7,327,865 | How do I know if my iterator was decremented past the beginning of my vector? | I am moving an iterator backward and forwards through a vector.
I can check if the iterator ran off the end like so:
++my_iterator;
if ( my_iterator == my_vector.end() )
{
--my_iterator; // if I want to stop the iterator at the end.
my_iterator = my_vector.begin(); // if I want the iterator to wraparound.
}
Bu... | I wonder if it would be easier for you if you used a Boost Circular Buffer instead of a std::vector as your underlying data structure.
But, to answer your actual question: You check for wrapping past the beginning by checking to see if the iterator equals v.begin().
#include <vector>
#include <cassert>
template <clas... |
7,327,728 | 7,374,426 | Communication between two computers without opening ports, using a third computer to set up the connection | Let's say I have a server, and two clients connected to it. (via TCP, but it doesn't matter)
My goal is to allow a direct connection between those two clients. This is to allow direct voice contact between two players, for example, or any other client plugin they may have installed which don't need server interaction (... | Punching TCP holes in NAT is sometimes/often possible (it depends of the NAT behavior). This is not a simple subject to learn, but read the corresponding chapter about NAT traversal from Practical JXTA II (available online on Scribd) to understand the nature of the issues to solve.
Then, read this. It comes from the gu... |
7,327,741 | 7,329,177 | initialisation of static object when linking against a static library | What are the rules for initialisation of static object declared in another shared library? For instance, consider the following:
file X.hpp:
struct X {
X ();
static X const s_x;
};
struct Y {
Y (X const &) {}
};
file X.cpp:
#include "X.hpp"
#include <iostream>
X::X ()
{
std::cout << "side effect";
}
X c... | By default on many platforms, if your program doesn't reference any symbols from a given object file in a static library, the whole object file (including static initializers) will be dropped. So the linker is ignoring X.o in libX.a because it looks like it is unused.
There are a few solutions here:
Don't depend on t... |
7,327,845 | 7,327,903 | Tracking code versions in an executable | I have a reasonable sized ( around 40k lines) machine learning system written in C++. This is still in active development and I need to run experiments regularly even as I make changes to my code.
The output of my experiments is captured in simple text files. What I would like to do when looking at these results is hav... | I generate a single source file as part of my build process that looks like this:
static const char version_cstr[] = "93f794f674 (" __DATE__ ")";
const char * version()
{
return version_cstr;
}
Then its easy to log the version out on startup.
I originally used a DEFINE on the command line, but that meant every versi... |
7,328,169 | 7,328,189 | How can I properly assign a char* in c++? | My c++ code looks like this:
char* x;
switch(i){
case 0:
x = '0';
case 1:
x = "1";
...}
I can't figure out how to make this work because for the first x = '0'; the compiler complains with:
error: invalid conversion from ‘char’ to ‘char*’
and for the second x = "1... | In case 0 you're trying to set x to a character (of type char), but in case 1 you're trying to set x to a C string (of type char const[2]). It's the type of quotes that make a difference; single-quotes are for characters, and double quotes are for C-style strings.
If you're meaning to set it to a string both times, put... |
7,328,327 | 7,328,340 | How to get file's owner name in Linux using C++? | How can I get get the owner name and group name of a file on a Linux filesystem using C++? The stat() call only gives me owner ID and group ID but not the actual name.
-rw-r--r--. 1 john devl 3052 Sep 6 18:10 blah.txt
How can I get 'john' and 'devl' programmatically?
| Use getpwuid() and getgrgid().
#include <pwd.h>
#include <grp.h>
#include <sys/stat.h>
struct stat info;
stat(filename, &info); // Error check omitted
struct passwd *pw = getpwuid(info.st_uid);
struct group *gr = getgrgid(info.st_gid);
// If pw != 0, pw->pw_name contains the user name
// If gr != 0, gr->gr_name con... |
7,328,389 | 7,328,474 | Allegro c++; flashing BITMAP | im trying to make a simple program that has one BITMAP that is the "background" and another BITMAP that i can move, ive tried different ways, like drawing the background directly to screen, tried making two buffers, ive tried putting both BITMAPS in one buffer. right now im running the program with both in the buffer c... | The code you have works like this:
// draw the my_pic sprite to bitty
draw_sprite(bitty,my_pic,my_pic_x,my_pic_y);
// status now: bitty contains my_pic
// draw bitty to the screen
blit(bitty, screen, 0,0,0,0,640,480);
// status now: screen contains my_pic by way of bitty
// clear bitty
clear_bitmap(bitty);
// status ... |
7,328,424 | 7,328,496 | Point in OBB (Oriented Bounding Box) algorithm? | Given a center point, width, height and angle forming an OBB, how can I find if a given point P is inside the OBB?
Thanks
| I take it that the wrinkle in your problem is that the bounding box can be rotated? If so, the easiest solution to me seems to be to do all calculations in the rotated coordinate plane, centered on the center of the bounding box.
To calculate the coordinates of the point relative to these axes:
newy = sin(angle) * (ol... |
7,328,463 | 7,328,554 | How to tell a C or a C++ compiler that pointers are not aliased | I have function that receives an array of pointers like so:
void foo(int *ptrs[], int num, int size)
{
/* The body is an example only */
for (int i = 0; i < size; ++i) {
for (int j = 0; j < num-1; ++j)
ptrs[num-1][i] += ptrs[j][i];
}
}
What I want to convey to the compiler is that the po... | restrict, unlike the more common const, is a property of the pointer rather than the data pointed to. It therefore belongs on the right side of the '*' declarator-modifier. [] in a parameter declaration is another way to write *. Putting these things together, you should be able to get the effect you want with this fu... |
7,328,545 | 7,328,656 | Access iOS settings from code |
Possible Duplicates:
Programatically access iPhone System Setting
How do I access the iPhone's settings from my code?
How to access iPhone general accessibility settings with OS 4.0
How to access iPhone's general accessibility settings
iPhone Settings
Access iphone setting preference
Is there a way to, from my code q... | No. In general, you can read your own app's preferences (whether they're set via the Settings app or by your app) using NSUserDefaults. You cannot, however, read the preferences for other applications, including system settings. There may be cases where you can figure out what the setting must be by using API specific ... |
7,328,632 | 7,328,651 | "Press any button to continue" in Visual Studio Express C++? | When creating an console application (blank document) how can I get the "Press Any Button To Continue" to automatically show up?
| You can add it manually with a
system("pause");
*Be carefull, this is not portable (will work on windows, but might not work elsewhere)
|
7,328,735 | 7,328,752 | How to pass an array of C-Strings to a function | Normally I would just pass an array into a function, however, I am doing a homework assignment and my professor says to use an array of C-Strings and I want to use a function. However, I can not think of how to send this to a function. Any help would be great.
| Pass it as a double pointer:
type myFunc(char **array) {
...
}
|
7,328,745 | 7,328,757 | Type of the quotient of two integers | Consider the following:
int num = 5;
double total = num / 2;
Is it correct to say that the quotient of num / 2 is not a double because you need to parse the int to double?
| The technical answer is that the / operator produces an int when given two ints. This computation is done independent of its assignment to a double variable.
You actually do get a double value in the variable total, but it is 2.0, not 2.5. The integer 2 is cast to 2.0 in the initialization.
Your options, if you want ... |
7,329,019 | 7,329,100 | GNU GCC 4.6(.1) compiler on Mac OS X Lion | Pretty new to this kind of development. Wondering if anyone can point me in the right direction. As far as I can see it, using MacPorts has an error where it doesn't work. However, I was reading around and saw this: http://beardedcodewarrior.net/2011/07/25/building-gcc-4-6-1-on-mac-os-x-lion/ but still couldn't get it ... | There are three likely possibilities:
It installed correctly and went into a directory earlier in your $PATH than your previous GCC installation, but Bash's internal hash table entry is still pointing to the old GCC.
It installed correctly but went into a directory later in your $PATH than your previous GCC installati... |
7,329,397 | 7,329,678 | What does GL_TEXTURE_3D mean? | As I know the texture is just an image (absolutely 2D), so why do we have GL_TEXTURE_3D? What does it mean? and usage?
| A texture is not absolutely 2d. Most of the time it is 2d but you can also have 1d textures (a line) and 3d textures (a volume). A 3D texture is accessed using three texture coordinates. You can use it when your 3d model can be clipped by a plane. Then instead of seeing the other side of the object (the object is hollo... |
7,329,566 | 7,329,622 | Why does a C comment like /* */ need '<'? | My teams C-code guidelines write that it'd be better to place a '<' in a comment like shown below:
#define MAX_PACK_ITEM_NUM 50 /**< max number of item */
I wonder, what is the real use of this '<' ?
| It's a way for doxygen to generate documentation for members of a file/struct/union/class/enum. By using that marker, you can put comments after each member, leading to less clutter. You can read more about it here.
|
7,329,617 | 7,330,574 | A destructor Shall OR shall not be declared with a pointer ? in C++ | In C++0x -n3290 Draft : they added in section :Destructors : 12.4/2nd point last line
**A destructor shall not be declared with a ref-qualifier.**
In c++03 Draft .... they didn't mention this point in destructors ?
my question is whether
*~S() ; //this declaration is allowed or not according to the S... | You have misunderstood what ref-qualifier means in the new standard. In the same way that you can provide a const qualifier to any member function in C++03, you can also add a ref-qualifier to a member function in C++0x. That modifier will affect the type of the implicit this argument to the function:
struct test {
... |
7,329,840 | 7,329,866 | printf not printing the correct values | I wrote a small code of C.
#include<stdio.h>
int main()
{
int a = 0;
printf("Hello World %llu is here %d\n",a, 1);
return 0;
}
It is printing the following ouput
Hello World 4294967296 is here -1216225312
With the following warning on compilation
prog.cpp: In function ‘int main()’:
prog.cpp:5: warnin... | %llu expects a 64-bit integer. But you only gave it a 32-bit integer.
The effect is that what printf is reading is "shifted" over by 32-bits with respect to what you've passed. Hence your "1" is not being read in the right location.
EDIT:
Now to explain the output:
a and 1 are being stored 32-bits apart because they ar... |
7,329,865 | 7,335,155 | Easiest way to do remote calls between a C++ program and a .NET program | I have a .NET program running in the background and need to create a Windows Shell Extension that can communicate with that program. At first I thought I would create my Shell Extension in .NET and used IpcServerChannel and IpcClientChannel to make remote calls between server (.NET program) and client (.NET Shell Exens... | Well, you could try SendMessage(WM_COPYDATA).
But then, if you are into it, it would be far more extensible (and maintenable) do just do a named pipe or a local inet socket. Actually, designing a communication protocol is not as difficult as it sounds: just send a serialized struct with the parameters and wait for a s... |
7,330,062 | 7,331,126 | How to resolve the issue "No source available for "msvcrt!fgets() " " | Code
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
class Chkinval
{
char *inval;
char *inarray;
public:
void inPutProcessor();
};
void Chkinval::inPutProcessor()
{
cout << "Input" ;
fgets(inval,1000,stdi... | The problem with the code as it is now is that neither inval nor inarray are initialized and you're thus reading up to 1000 bytes into some arbitrary memory location.
for(int lpcnt=0;lpcnt< tmp;lpcnt++)
{
fgets(inarray,1000,stdin);
}
Is probably also not what you want (even if inarray was initialized) since ... |
7,330,063 | 7,330,119 | Sorting one array and two others array follow | Suppose we have three arrays a, b, and c:
int a[1000] = {3,1,5,4};
int b[1000] = {7,9,11,3};
char c[1000] = {'A','B','C','D'};
Array a is then sorted, so it becomes:
a == {1,3,4,5}
Is it possible to arrange for the other two arrays to have their elements rearranged by index, so that they mirror the placement of the s... | you can create a class ABC, which will hold 3 fields: int a, int b, char c.
implement the operator< for this class, and create a ABC[] of the approppriate size and populate it such that ABC[i] = ABC(a[i],b[i],c[i]).
implement the operator< so it will compare only a, and use sort on the ABC array.
after done sorting, yo... |
7,330,090 | 7,330,127 | Magick++ linking error | I have here a simple image converter code using Magick++(ImageMagick interface) library.(Eclipse IDE)
#include <Magick++.h>
#include <string>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
Image image;
image.read("/home/usr1/test.tiff");
image.write(... | Try inverting the Magick libraries, add the MagickWand library (and put libz and other base image libraries at the end, and the dynamic linker library while you're at it):
... -lpthread -lMagick++ -lMagickWand -lMagickCore -lz -ldl
See Linker Order - GCC for why the order of static libraries matters.
|
7,330,168 | 7,412,790 | net-snmp sample code to parse MIB file and extract trap related information from it | I am using the net-snmp C library on Windows. I want to parse trap-related information from the MIB files.
I need some sample code to do this. I didn't find anything useful on http://www.net-snmp.org/
| Here is some sample code to parse MIB files using the net-snmp library.
Before you use this code you need to refer or add the Include and Lib directories of net-snmp in your project properties:
#include "stdafx.h"
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/definiti... |
7,330,268 | 7,330,417 | Is it possible to run Win32 executable on a virtual private server (VPS)? | Is it possible to run Win32 executable on a virtual private server (VPS)?
I have created some .exe application from C++ code, and I need to let people on the internet run it, is it able to do so on a VPS? or I have to rent dedicated server?
I will take input from HTML form, pass it to PHP, and from PHP call 'system' to... | There shouldn't be a problem running a Windows executable on a Windows server as long as the executable is compatible with the Windows version used.
This is assuming that you have Administrator rights on your VPS, can install the application, and sort out any permissions problems that might arise at first.
|
7,330,287 | 7,330,344 | Best and safe way to transfer data over a pipe on different platform | Currently I am facing an issue where i am passing a buffer object over a pipe from x64 arch to x86 arch. The object also contains some pointer values, which is 8 bytes in x64 which the same pointer size on x86 is 4 bytes. Now when i am transmitting the object over pipe then size of it is bit more than what x86 platform... | boost serialization is designed specifically to :
Here, we use the term "serialization" to mean the reversible
deconstruction of an arbitrary set of C++ data structures to a
sequence of bytes. Such a system can be used to reconstitute an
equivalent structure in another program context. Depending on the
context... |
7,330,296 | 7,330,341 | Constructor Overloading in C++ | My C++ overloading does not act as I assume it should:
#include "Node.h"
#include <iostream>
Node::Node()
{
cout << "1" << endl;
Node(Game(), 0.0);
}
Node::Node(double v)
{
cout << "2" << endl;
Node(Game(),v);
}
Node::Node(Game g, double v)
{
cout << "3" << endl;
numVisits = 0;
value = v;... | Node(Game(),v); in your constructor doesn't do what you expected. It just creates a temporary without using it and makes no effect. Then it immediately destructs that temporary when control flows over the ;.
The correct way is initializing the members in each constructor. You could extract their common code in a priva... |
7,330,364 | 7,330,382 | GDB: warning: Multiple breakpoints were set on overloaded methods | anisha@linux-dopx:~> g++ -Wall -pedantic breakpoints.cpp -g
anisha@linux-dopx:~> gdb a.out
(gdb) b X::X
Breakpoint 1 at 0x400ac1: file breakpoints.cpp, line 14.
Breakpoint 2 at 0x400aa0: file breakpoints.cpp, line 9.
warning: Multiple breakpoints were set.
Use the "delete" command to delete unwanted breakpoints.
(gdb)
... | I think, this case is normal. Some ABI will generate two constructors for an Class. When you ask b X::X gdb will detect both constructors and set two breakpoints. (Sorry, this is not your case)
The "Multiple breakpoints were set." warning may be also given for overloaded methods (this is your case): http://www.delorie.... |
7,330,559 | 7,330,977 | to build cross platform async event based server that is working on windows and linux which lib to use? | after reading this great article im not sure how can i build simple cross platform server that can be has good as linux single event based servers . i didnt understand can it be done ? does boost aio is the right tool for this ? is there any other tool for this ?
im using c++ as the programming .
typedef struct {
un... | I would also recommend the Adaptive Communication Environment http://www.cs.wustl.edu/~schmidt/ACE-overview.html. But if you already use Boost in your existing code, boost::asio is a wonderful library to work with too.
|
7,330,618 | 7,349,317 | What is the barebones C++ code necessary to put a jpeg into MySQL table? | I have created a MySQL table where one of the columns stores a BLOB type. (The Internet told me BLOB is the correct data type for images.)
I am pretty much a beginner with both C++ and MySQL. What I would like to do is to write a small program with a main() that puts a jpeg into that table. For the sake of this exercis... | For this scenario, a good solution would be to use the mysql_stmt_send_long_data() function.
There is an example on the MySQL Manual page that I linked to, but here is a more relevant example of sending file contents:
#ifdef _WIN32
#include <windows.h>
#endif
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#in... |
7,330,685 | 7,333,477 | Waking a boost::sleep timer and reset it to 0 in C++ | I require a heartbeat signal every 10 seconds or so. To implement this I have produced a class with the following constructor:
HeartBeat::HeartBeat (int Seconds, MessageQueue * MsgQueue)
{
TimerSeconds = Seconds;
pQueue = MsgQueue;
isRunning = true;
assert(!m_pHBThread);
m_pHBThread = shared_ptr<thread>... | Perhaps you can use interrupt() to do this.
|
7,330,965 | 7,331,024 | Common constants for an AVR / Linux GCC C++ project | I'm creating software for an Linux + AVR Arduino project. Obviously the whole work is split in several projects in Eclipse (I'm not using Arduino IDE). I'd like to use common, mostly string, constants for all those projects. I also have to spare microcontroller's RAM so compile-time constants needed. How do I best impl... | You can continue with the current idea of using const char* const (if std::string is not usable). I would suggest to use #define for assignment purpose only. Example:
class A {
public:
static const char * const STRING_PART1;
static const char * const STRING_PART2;
static const unsigned char BOOL;
};
#define... |
7,331,085 | 7,331,370 | Unresolved external using template class with copy-and-swap | I'm getting a linker error when using a template class where I tried implementing the copy-and-swap idiom as suggested here:
What is the copy-and-swap idiom?
The template class, let's call it "TemplateClass" is partially defined like this:
template< class T >
class TemplateClass
{
// ...
TemplateClass< T >& ope... | This is a common problem when befriending non-member functions with templates. The friend declaration inside the TemplateClass does not befriend your swap template, but rather a non-templated free function swap that takes TemplateClass<T> for which ever T the template is instantiated (i.e. the specialization TemplateCl... |
7,331,122 | 7,335,604 | Array of functions with different signatures | I have this classes:
class Foo
{
...
};
class Foo1 : public Foo
{
...
};
...
class FooN : public Foo
{
...
};
Is it possible to have an array of functions with these kind of signatures:
void f1(Foo1*){}
...
void fN(FooN*){}
Is there any change if these functions are non static member functions instead ... | I found this workaround for this problem:
#include <iostream>
#include <vector>
class Foo
{
};
class Foo1 : public Foo
{
};
class Foo2 : public Foo
{
};
class Foo3 : public Foo
{
};
void f1(Foo1*)
{
std::cout<<"f1\n";
}
void f2(Foo2*)
{
std::cout<<"f2\n";
}
void f3(Foo3*)
{
std::cout<<"f3\n";
}
tem... |
7,331,661 | 7,332,206 | Debugging DirectShow Filter | I'm developing a DirectShow filter that it's input connects to H.264 encoder's output,
the filter purpose is to insert FEC bits just before the H.264 NAL's header,
what requires me to read the encoder's data on the bit LEVEL.
I already made the FEC filter DLL and connected it using GraphEdit.
Suppose I want to see s... | there're two possibilities:
1) implement logging of anything you need to know to external file in you FEC filter
2) you can put "smart tee" filter before (and/or after) your FEC filter to "tee" the stream and connect the second pin to "dump" filter (http://msdn.microsoft.com/en-us/library/dd388553(v=vs.85).aspx) that c... |
7,331,692 | 7,331,702 | why can't i include a static library into a cpp file? | Is there a way to #include "library.a" or it's .so or it's .o inside a cpp or cc file?
I would like to do this because I am using this file inside another file.
| #include is for C++ code.
.a, .so and .o files are not C++ code.
It's more likely that you want to #include a C++ header file (typically ending in .h or .hpp), and link an object file.
|
7,332,118 | 7,397,180 | antialiasing leaves thin line between adjacent widgets | I have two widgets that both have a dark background of the same color. These widgets lie in adjacent cells within a QGridLayout which has ContentsMargins and spacing of 0 on all sides. I use a custom QStyle-derived class for drawing.
If I don't use antialiasing, everything looks as expected - the two widgets' backgroun... | Try to shift by half-pixel, either when creating the path or by translate(0.5, 0.5) after setting the render hints.
|
7,332,162 | 7,332,324 | How to render a texture with alpha? | How to render a texture with alpha?
I have a texture, and need to render it with different alpha values at different locations. Any way to do so? (My texture is GL_RGBA)
If not possible to change alpha value on the fly, I have to create different textures for different alpha levels?
| Your texture is GL_RGBA so it has a different alpha value for each texel.
If you want to change the alpha value used for render, I can think of the following methods:
Change the texture alpha values (not sure if you say that you don't want to do that).
Use glColor4f to change the alpha value of the vertices. It will m... |
7,332,165 | 8,244,989 | How do I best read a boost serialization archive? | I guess my question derives partially from this question: std::ifstream buffer caching. I have a boost serialization archive, and am currently reading out of it with the & operator as suggested on the help. My understanding is this translates to << and >> for input and ouput operations. Now judging from above question,... | Changing it doesn't make sense. By default, it goes through a buffered reader anyway, and this reader anyway reads off the hard drive in 4k chunks. Reading them one by one allows for better memory recycling. The only thing that might make sense is to change the 4k to a different number.
|
7,332,279 | 7,332,416 | Sub-classes, assignment operator overloading? | If I have the given below classes:
class TestA
{
public:
const TestA &operator=(const int A){return *this;}
};
class TestB : public TestA
{
public:
//Inheritance?
};
The question presumes both class TestA and class TestB have exactly the same contents in terms of variables: Is the assignment o... | Assignment operators are hidden by derived class by default (as compiler always generates a T& operator = () for any class T, if not specified). Which makes the inherited operator = not usable.
Yes when you specify them with using keyword; they become usable. Demo. So your code snippet does make sense.
public: using Te... |
7,332,316 | 7,344,539 | Does the Chromium project use a file management library? | Does the Chromium project use a cross-platform file management library that:
Copies files
move files
deletes files
If so, which library?
| Whilst I'm not familiar with the Chromium source code you should find, as mentioned in the comments, that the Boost Filesystem library gives you what you're asking for.
|
7,332,373 | 7,332,404 | How to return more than one value from a C++ function? | I am interested if I can return more then one value from a function. For example consider such a function: extended euclidean algorithm. The basic step is described by this
Input is nonnegative integers a and b;
output is a triplet (d,i,j) such that d=gcd(a,b)=i*a+j*b.
Just to clarify my question's goal I will write a... | Just create an appropriate data structure holding the three values and return that.
struct extmod_t {
int d;
int i;
int j
extmod_t(int d, int i, int j) : d(d), i(i), j(j) { }
};
…
extmod_t result = extendedeuclidean(b, q);
return extmod_t(result.d, l, k - l * r);
|
7,332,383 | 7,333,209 | Inheritance from macros in Qt4 | Part of my code looks something like this.
#include <QObject>
#define MYMACRO : public QObject
#define SIGNAL_MACRO Q_OBJECT signals: void testSignal(std::string s);
#define EMIT_MACRO emit testsignal(s);
class myclass MYMACRO
{
SIGNAL_MACRO
...
void myclass::method()
{
std::string s("string");
EMIT_MACRO
}
... | I think the problem here might be that the Qt meta-object compiler is run before the C++ pre-processor, so it doesn't get to see the Q_OBJECT inside the SIGNAL_MACRO. From the Qt Reference Documentation:
The moc tool reads a C++ header file. If it finds one or more class
declarations that contain the Q_OBJECT macro,... |
7,332,423 | 7,332,456 | Undefined reference C++ | I have a file called Student.h which have the static integers in this way:
class Student
{
public:
static int _avrA,_avrB,_avrC,_avrD;
};
and I have university.h that inherits Student.h .
On the implementation of University.cpp , one of the functions returns:
return (_grade_average*(Student::_avrA/Student::_a... | You have declared those variables, but you haven't defined them. So you've told the compiler "Somewhere I'm going to have a variable with this name, so when I use that name, don't wig out about undefined variables until you've looked everywhere for its definition."1
In a .cpp file, add the definitions:
int Student::_av... |
7,332,474 | 7,332,563 | Can't compile Qt Creator | I'm trying to compile Qt Creator source code and got the following error message:
fatal error: QtCore/private/qwineventnotifier_p.h : No such file or directory.
I'm on Win XP SP3 using QtSDK version 1.1.3, MinGW (g++ 4.5.2). In the QtCore folder of the QtSDK includes there is no any folder named private, and searching... | [Edit:]
Apparently there's an issue with this recently:
https://bugreports.qt-project.org//browse/QTCREATORBUG-3701
https://bugreports.qt-project.org//browse/QTBUG-17218
You my try getting the file from somewhere, e.g.:
http://cep.xor.aps.anl.gov/software/qt4-x11-4.2.2-browser/df/d69/src_2corelib_2kernel_2qwineventnoti... |
7,332,566 | 7,332,584 | Why should I need libprofiler.so.0 | I am using google prof tools, and link my app with -lprofiler, but when I run this program:
error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory
on the contrary, I link with -ltcmalloc then I do not need a tcmalloc.so at runtime.
I have already link the stati... | The static library just contains stubs for calling actual functions from the shared object dynamically. So you will need the .so as well. The static library makes your life easier, so that you don't have to write GetProcAddress() or whatever it is on your system.
|
7,332,616 | 7,332,645 | static member in c++ | I was experimenting with static keyword in c++. The following class has a static variable called size which is initialized as 10.
class staticTest
{
public:
static int size;
int x,y;
staticTest()
{
x=0;
y=0;
}
... | Only compile-time constants can be used as array sizes.
Declare your integer as static const int.
Also, the (default) value needs to go in the declaration, not the definition:
// in header
class Foo {
public:
static const int n = 10;
};
// in implementation
const int Foo::n;
Based on your comment, consider this: A... |
7,332,625 | 7,332,689 | VS2008 C++ lib project property setting problem | I created a C++ static library project in VS2008 using the wizard as following:
-Win32 application
-In "Application Settings", selected "Static Library"
-unchecked "Precompiled Header"
After it completed, I found that under "Project Properties->Configuration Properties", there is no "C/C++" section. I tried to create... | "C\C++" section is presented only if you have any c\c++ files added to the project. In opposite case this section is useless because your library is not C\C++ library
|
7,332,696 | 7,332,761 | What is the difference between mblen and strlen? | What is the difference between mblen and strlen?
Is today multi-byte character encoding used in Windows, Linux or Mac OS? Is multi-byte character encoding same as fixed-width character encoding in Windows?
| strlen takes the length of a const char *, and assumes that one char takes one byte, so it counts the chars until a null terminator ('\0') has been encountered, whereas mblen takes a pointer also of type const char *, but this points to the first byte of the multi byte character.
For more info on what are multi-bye cha... |
7,332,786 | 7,336,881 | understanding of the creating dll in visual studio | I created some simple dll in visual studio, to begin to use it I read the following article:
To use the functionality from the class library in the console
application
1) After you create a new console application, an empty program is
created for you. The name for the source file is the same as the name
that you... | Step 2 and 3 describe steps to help create a managed project, one that uses the .NET framework.
It is calling referencing an assembly, and is equivalent to linking in a library file for native apps.
I take it you are creating a C++/CLI managed application?
|
7,332,875 | 7,333,153 | How do I step-over or continue after a c assert in ios/xcode? | I have searched, but cannot find how (or if) I can step over or continue after a c assert() in xcode 4/ios 5.0. I am using c++ not objective-c. Will I need to define my own assert to achieve this?
Thanks~
| Asserts aren't normally meant to be ignored. They are there for the programmer to communicate to other programmers that "this should never, ever happen". If you're curious to see what happens if you continue past the assert, comment it out and see how your program behaves after the point where it would normally fail.
|
7,333,201 | 7,333,225 | Use << operator with pointer to char | There is an operator overload for << which interprets char* as a C-style string. If char* however points to a single character, how do I output it into a stream?
| If ch is of type char* and actually points to a single char, use *ch so that the type of the expression is char. The operator will know what to do.
|
7,333,256 | 7,333,295 | How can I convert from ANSI character (char) to Unicode character (wchar_t) and vice versa? | How can I convert from ANSI character (char) to Unicode character (wchar_t) and vice versa?
Is there any cross-platform source code for this purpose?
| Yes, in <cstdlib> you have mbstowcs() and wcstombs().
I've previously posted some code on how to use this, maybe that's helpful. Make sure you run the function twice, once to get the length and once to do the actual conversion. (Here's a little discussion of what the functions mean.) Instead of the manual char array, I... |
7,333,281 | 7,333,367 | Operator Overloading in C++ | I need to overload the * operator in c++. So I have made a class called Element which must overload this opperator to work on a double value stored within it. This is what I have done in the implementation file:
#include "Element.h"
#include <iostream>
using namespace std;
// Other code that is not relevant
Element ... | You really have to understand what you are doing here, you are overloading the '*' operator for the Element class, but you're doing so while expecting another element has a 'parameter'.
The code you wrote is actually expecting this kind of code
Element v, w, a;
a = v * w;
As mentionned, you might want to take a look a... |
7,333,419 | 7,333,492 | Multiple inheritance with QThread and QWidget ( Multiple inheritance with QObject ) | I'm going to design OgreWidget class -A portable renderer widget with Qt.
(With my design), I think my class need to be inherited with QThread (for infinite render loop ) and QWidget ( target widget for ogre to render there) .
But according to many documentation and articles (for instance this), Virtual inheritance wit... | That's impossible, because both QThread and QWidget in the end resolve to QObject base class
This thread answers your question:
how can i inherit from both QWidget and QThread?
|
7,333,730 | 7,333,914 | Inheritance and destructors - theoretical question - C++ | class A
{
public:
virtual void f(){ printf("A.f "); }
~A(){ f(); }
};
class B : public A
{
A a;
public:
void f(){ printf("B.f "); }
B(){ throw -1; }
~B(){ f(); }
};
int main()
{
try{ B b; }
catch(...){ printf("Exc");}
}
So here's how I see it. Inside t... | You really have two A objects here.
B inherits from A, so a base class object of A is instantiated first before B is.
Another A instance is created as you have a member field of type A as part of B.
When you create B b, you create the base class A, and also the instance A a.
However, you then throw the exception in B... |
7,333,870 | 7,334,567 | C++ subclasses modular functions | Sorry, I decided to radically update the question given the code was riddled with my errors and didn't convey my point.
I wanted to see whether or not the below is viable:
Here's an example that can be compiled:
#include <stdio.h>
class TestA
{
public:
int A;
TestA(){A = 1;}
const TestA &o... | vi·a·ble
Adjective/ˈvīəbəl/
Capable of working successfully; feasible
If it works, it's viable.
In your case, it works. However, consider these 2 scenariosn:
-You might add virtual functions. That will cause it to crash.
-You might change AdvancedFunction1() so that it operates on members of the class TestB, which w... |
7,334,081 | 7,334,176 | gsoap - compile using -lcrypt | I am working in ubuntu under c++ code. I am using gsoap in order to connect to a server. I've obtained all the data necesarry. I've also succeeded to connect to the server. Still I do have a question. Why do I need to write in the command line: g++ test_server.cpp -o testServ libgsoap++.a. Why do I need to include libg... | You need to tell g++ that you want to link against libgsoap++ using -lgsoap++.
If you want to link against non-system-wide version of libgsopa++, you need to specify library path to g++ via -L flag.
Short explanation:
You have link-time error. The compilation was successful and produced object files. During compilation... |
7,334,269 | 7,334,353 | undefined reference to 'vtable for classname' |
Possible Duplicate:
Undefined reference to vtable
I have a class Student on the file - student.h
and this is its constructor:
class Student
{
protected:
double _id;
double _salary;
double _grade_average;
public:
Student(double id, double salary,double average):
_id(id),_salary(salary),_grade_avera... | A couple of things.
Put the underscore after the variable name. As names that start with
an underscore may be used by the compiler.
Make sure to define at least one virtual function if you plan on
inheriting from it or using RTTI. (ex. a Virtual Destructor)
Make sure that every declared function has a corresponding
im... |
7,334,343 | 7,345,354 | libcUrl Bad request. Seem that POST body isn't sent, only header | I use this options:
curl_easy_setopt(curl, CURLOPT_URL, urlUpload);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_POST, 1)... | My error was because of the mistake in the POST body. SO this cUrl option is the right way to form POST request with header.
|
7,334,632 | 7,334,693 | Connect to oracle database with C++ | I am looking for a way to connect to an remote oracle database and read some data from table within a c++ console application.
Can some one give me some hints.
Thnx.
| soci, http://soci.sourceforge.net, is a reasonably modern C++ interface that uses the Oracle call interface. And can also connect to other databases ...
|
7,334,832 | 7,334,895 | Are 'addition' and 'bitwise or' the same in this case? | Say I have four 32-bit numbers, defined so that their bits don't overlap, i.e.
unsigned long int num0 = 0xFF000000;
unsigned long int num1 = 0x00FF0000;
unsigned long int num2 = 0x0000FF00;
unsigned long int num3 = 0x000000FF;
Where in each number one could have anything in the place of the FFs.
Am I right in saying t... | as long as for two numbers num1 and num2 applies num1 & num2 == 0, then follows:
num1 + num2 == num1 | num2
the reason for this is, that addition is basically a bitwise XOR, plus carry bit. But as long as there are no carry bits (num1 & num2 == 0) then addition boils down to bitwise XOR, which is (again because of num1... |
7,334,839 | 7,340,845 | How to get environment variable from FastCGI C++ binary during startup | I have a FastCGI application that loads and processes a lot of data during its startup. And I want it to get some environment variable to determine its input data path, but as much as I understand so far, environment pointer envp comes with the request.
I want to do getenv before the very first request, say directly af... | Yeah, as it turnes out, the lighttpd's counterpart to -initial-env is "bin-environment" array in the fastcgi.server section of lighttpd.conf. The values defined there are accessible for getenv() from the very beginning of execution.
|
7,334,909 | 7,336,253 | QString::startWith() & QStringList::removeAll() not behaving as expected | I have two lists. Both containing the same values:
QStringList filePaths;
filePaths.append("C:/backup");
filePaths.append("C:/download/file1");
filePaths.append("D:");
filePaths.append("C:/program");
filePaths.append("C:/download");
QStringList refinedPaths;
int size = filePaths.size();
for(int i = 0; i < ... | Your code works fine, not sure what problem you are referring to. Using your code here's the output I got
C:/backup
D:
C:/program
C:/download
A few things to improve,
instead of copying QStringList element by element you can just use the copy constructor i.e copying from filePaths to refinedPaths QStringList refined... |
7,334,941 | 7,339,703 | Link error: undefined reference to EVP_CIPHER_CTX_ and EVP_CIPHER_CTX_init | I am using crypto++ in my code. I don't want to use its dependencies so i've tried to import crypto++ files in my folder and include them in my .cpp file
I have the followng errors:
TEST.cpp:(.text+0x89a0): undefined reference to `EVP_CIPHER_CTX_init'
TEST.cpp:(.text+0x8cb0): undefined reference to `EVP_aes_128_cbc'
TE... | You need to do two things, of which you've only done one so far.
You need to tell your compiler where to find the appropriate declarations. You've done this by adding
#include "evp.h"
in your source file. (Depending on how you installed crypto++, you might also need to tell the compiler where to find "evp.h", probab... |
7,334,952 | 7,334,968 | Will using goto leak variables? | Is it true that goto jumps across bits of code without calling destructors and things?
e.g.
void f() {
int x = 0;
goto lol;
}
int main() {
f();
lol:
return 0;
}
Won't x be leaked?
| Warning: This answer pertains to C++ only; the rules are quite different in C.
Won't x be leaked?
No, absolutely not.
It is a myth that goto is some low-level construct that allows you to override C++'s built-in scoping mechanisms. (If anything, it's longjmp that may be prone to this.)
Consider the following mechani... |
7,335,063 | 7,335,143 | Question about passing class as alias parameter in C++? |
Possible Duplicate:
Why should the copy constructor accept its parameter by reference in C++?
I have the following code:
class Student {
private:
int no;
char name[14];
public:
void display() const;
Student(const Student& student); // Line 1
};
I have read that class is a reference type, so why in L... |
I have read that class is a reference type
In C++, the assertion that “class is a reference type” makes no sense. You may have heard this in connection with C# but this is a completely different matter.
Consequently, the whole discussion is moot. To understand the syntax of copy constructors you first need to underst... |
7,335,215 | 7,335,296 | How to get maximum frame size of each function compiled by gcc? | Is it possible to get maximum frame size of each function compiled by GCC?
I have a bunch of C and C++ source files in my project and I want to have a statistics of stack usage of each function, just couldn't find any related options in GCC manual.
| You can try -fstack-usage.
https://gcc.gnu.org/onlinedocs/gnat_ugn/Static-Stack-Usage-Analysis.html
There is also -Wstack-usage=<stack_limit> (eg. -Wstack-usage=4096) which will give you a warning as you compile your code.
|
7,335,433 | 7,429,424 | Uploading videos to ScreenCast.com in C++ | I need to write a C/C++ program that uploads videos to ScreenCast.com. For uploading videos to YouTube there is a great manual that explains how it can be done with an http request. I can't find something like that about Screencast.
Maybe someone has experience with this or some related tasks. I'm quite new to program... | The right answer is that for now it is impossible. I have contacted screencast.com support, and they told me that they are going to make a puplic API somewhen in future
|
7,335,546 | 7,335,623 | Find the first value greater than user specified value from a map container | I have a map container. How to return the first value greater than the user-specified search value by using find_if as follows:
std::map<string, int>::iterator it = find_if(Mymap.begin(), Mymap.end(), ......
Thank you very much!
| With a lambda:
int n = MYVALUE;
auto it = std:: find_if(Mymap.begin(), Mymap.end(),
[n](const std::pair<std::string, int> & x) -> bool
{ return x.second > n; }
);
(If the value is fixed you can put it directly inside the lambda body. For C++14 and ... |
7,335,652 | 7,336,069 | How should I design a set of related classed where only some of them support a certain operation? | I am working on a slide-based application in C++.
Each slide has a slide-items collection which can
include items like caption, button, rectangle, etc.
Only some of these items support fill, while others
don't.
What is the best way to implement the fill for the slide items in this case?
Here are two ways that I thought... | I would do a combination of the two. Make your Fillable interface and have it be the return type for your GetFill method. This is better than the dynamic cast approach. Using dynamic cast to query for the interface requires that the actual slide item object implement the interface if it is to support it. With an ac... |
7,335,746 | 7,338,639 | Full HD 2D Texture Memory OpenGL | I am in the process of writing a full HD capable 2D engine for a company of artists which will hopefully be cross platform and is written in OpenGL and C++.
The main problem i've been having is how to deal with all those HD sprites. The artists have drawn the graphics at 24fps and they are exported as png sequences. I... | 24 fps hand-drawn animations? Have you considered reducing the framerate? Even cinema-quality cel animation is only rarely drawn at the full 24-fps. Even going down to 18 fps will get rid of 25% of your data.
In any case, you didn't specify where your load times were long. Is the load from harddisk to memory the proble... |
7,335,750 | 7,335,872 | Class Just For Semantics | I am building an application that allows you to apply styles to regular expressions and their capture groups. I have a class called RegexGroup which contains a list of RegexGroup's and Regex's.
I will make a gui front-end in order to utilize these classes and I started by making a Project class that will be serializabl... | If a Project is actually a RegexGroup . Then you could just derive from it.
It makes perfect sense, if you say something is another, then that's where you derive from it.
class Project: public RegexGroup { }
And of course, along the way you might find subtle differences where you could add stuff to the separate classe... |
7,335,820 | 7,336,187 | partition of multidimensional array | i am trying to implement following algorithm:
suppose there is array a[3][3], my aim is choose some pivot element,for example a[1][1] and make partition such that, all element less then a[1][1] must be on left side and above the pivot element, and all greater element on the right side and below pivot element. ... | Your problem as stated does not have a general solution. Specifically, there is no guarantee that all of the values less than the initial pivot value will fit to the left of the initial pivot point, nor that all of the values greater than the initial value will fit to the right of the initial pivot point.
You need to r... |
7,335,833 | 7,339,733 | how to choose SQLite date format | Sqlite has a different approach in storing time than other databases:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
**TEXT** as ISO8601 strings ("YYYY-MM-DD ... | Is this correct?
Format Resolution Min Year Max Year Bytes/Date
Text Milliseconds 0 AD 9999 AD 23 or 46
Real Milliseconds? 4713 BC ???? 8
Integer Seconds 1970 AD ???? 8
|
7,336,185 | 7,336,219 | What is the purpose of GetPrivateProfileString? | I have come across the term GetPrivateProfileString in a C++ program. Could anyone give me a simple explanation of the use of this function?
The code on my page is:
GetPrivateProfileString("files", "directory", "/mediadb/files/", directory, os.path.getsize(directory), "apache")
| GetPrivateProfileString() reads values from .ini files.
Way back when, in the days of 16-bit Windows, it was the way to read and write application configuration data. Back then applications stored their configuration in a shared .ini file that lived in the system directory, called win.ini. Bad times!
To read from win.i... |
7,336,287 | 7,338,176 | gtkmm: Modal widgets within window | I have the following issue: I created a program which prompts the user for some input. This is done using a derived Gtk::Dialog that is used like follows:
if (modal_dialog->run() == SUCCESS){
// do stuff depending on modal_dialog inputs here
}
Now, I would like to replace the dialog by an embedded widget that is sho... | Instead of calling run() You can create a local loop object and make a nested loop. I don't know gtkmm very well, but the gtk+ code would be:
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
g_main_loop_unref(loop);
Now, in the clicked event of your Ok/Cancel buttons simply call g_main_loop_quit(... |
7,336,303 | 7,336,429 | std::multimap getting two ranges | I'm using a C++ std::multimap and I have to loop over two different keys. Is there an efficient way to do this other than creating two ranges and looping over those ranges seperately?
This is the way im doing it now:
std::pair<std::multimap<String, Object*>::iterator,std::multimap<String, Object*>::iterator> range;
st... | The code you started with is the most straightforward.
If you'd really like to iterate over two ranges in the same loop, you can create a custom iterator that takes two iterator ranges, iterates over the first until it's done then switches to the second. This is probably more trouble than it's worth, as you'd need to i... |
7,336,488 | 7,336,728 | thread safety of a class imported from dll | I have a dll which exports the interface
class Qwe{
virtual void a() = 0;
virtual void b() = 0;
};
extern "C" Qwe* createQwe();
I load it in my program and create multiple Qwe objects. The question is whether accessing those objects from different threads is safe? Shall I open the new library instance for eac... | In windows you can only load a library once. Further attempts to load a library only increments a reference counter. So therefore 'loading a library for each object' is a non-starter.
If your Qwe class contains data members or fields, which I can't tell if it does or not, than you could protect access to shared memory ... |
7,336,649 | 7,336,714 | C++ classes prototype conflict | Given the below classes are in two separate header files and can appear in any order:
//TestB.h
class TestB; //Forward declaration for a later operator= in a centralised header
class TestA
{
const TestA&operator=(const TestB); //defined in Test.h
};
And:
//TestA.h
class TestA; //Forward declaration for a later op... | You pass references to the classes as parameters. This way, a class and its member functions can be declared without knowing about the other.
//TestB.h
class TestB; //Forward declaration for a later operator= in a centralised header
class TestA
{
const TestA&operator=(const TestB &); //defined in TestB.h
};
And:... |
7,337,248 | 7,342,195 | Boost Asio Peek and Completion Condition | I am using Boost Asio to set up a socket connection. I would like to peek at the data in the buffer without consuming it, and I would like to use a completion condition to ensure that I could stop the blocking call if necessary.
I can get the peek functionality from basic_stream_socket::receive:
template<
typename... |
I would like to peek at the data in the buffer without consuming it,
and I would like to use a completion condition to ensure that I could
stop the blocking call if necessary.
Don't do this. Use asynchronous methods such as async_read() and async_write(). To stop outstanding asynchronous operations, use cancel().... |
7,337,357 | 7,337,494 | Why is my detoured code, crashing with a NOP | Hi this is my first question so please treat me gently.I am detouring an exe, using MS detours and Visual Studio 2005, my dll gets loaded and my hook works a treat however when I try to extend my hook code something is going wrong and the whole thing crashes, I think its creating an exception in the exe which is poppin... | How do you know there is something in eax ?
In general, detour crashes are often due to an inaccurate calling convention and/or prototype. I suspect that the detoured function returns a void* or something else. You need to capture the return value and pass it along to the caller once you're done, like so:
typedef void... |
7,337,414 | 7,337,650 | How can I make std::find_if and std::map work together using some boost library? | This question is inspired from another topic which poses this question:
Find the first value greater than user specified value from a map container
which can be solved in several ways. A typical C++03 solution defines a dedicated function (or functor) and pass it to std::find_if as third argument.
In C++11, one can a... | Indeed, Boost.Fusion and Boost.Phoenix have exactly what you want built-in.
If one includes the necessary header to adapt std::pair<> as a conforming Fusion sequence, then one can use Phoenix's lazy version of boost::fusion::at_c<> to access std::pair<>::first or std::pair<>::second (be sure to #include <boost/phoenix/... |
7,337,435 | 7,338,594 | Approaching serialization without common base class | I am looking for some design advices for the following problem:
I am using boost geometry, I have a couple of custom geometry types compatible with boost geometry (via traits), but most of the types I am using are typedefs.
class MyPoint
{
// custom stuff
};
// declare traits for MyPoint for use wih boost geometry he... | Boost's serialization supports non-invasive serialization if you do not wish to reimplement the wheel. You may even be able to find library support for their geometry types somewhere. The interface is somewhat complicated due to XML concerns unfortunately.
|
7,337,637 | 7,337,776 | Easiest way to limit executable to running on a certain computer | I am trying to create an executable that will only run on one machine. What is the easiest way to achieve this? A license file? Or is there a machine address much like the MAC for network connections I could hardcode into the executable?
| If it will run on only one machine, then... simply secure the machine and only store the executable on this machine.
That's, unfortunately, about the only reliable method.
Longer answer:
bits can be copied
programs can be dissassembled
dissassembly can be reverse engineered (though it's sometimes long)
the cost of re... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.