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 |
|---|---|---|---|---|
5,845,204 | 5,845,224 | Strange input from WM_CHAR - WinAPI | This is a continuation of my previous question: WinAPI: How to process keyboard input in custom edit control
I felt i should put this in a different question as the nature of the question is a bit different.
So my program is receiving input now, but the input is a bit off. The best way to explain is to just show you th... | MapVirtualKey accepts scan code for a key. But wParam in WM_CHAR is not a scan code - it is a char. You should use WM_KEYDOWN, wParam there is a scan code.
Links for you:
http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms646276(v=vs.85).aspx
|
5,845,212 | 5,845,287 | Cornered by const: std::map::find() const overload | Consider the following snippet:
#include <map>
class C {
public:
C() {}
const int& f(const int& x) const
{
// Error: cannot cast const int* to int* const
return myMap.find(&x)->second;
// With a const_cast works:
//return myMap.find(const_cast<int* const>(&x))->second;
... | The real question is: why isn't the index of the map a pointer
to const? (Supposing, of course, that it should be a pointer.)
Do you really want to be able to modify the index via something
like *myMap.find(&x)->first = xxx; I would say that that is
quite unusual, given that you already have a pointer to the
object.
|
5,845,232 | 5,845,305 | How to exit a program when user inputs a special character | i'm curently doing a simple program that consists of a while-loop that reads in two ints and then prints them out. My question is, how can I exit the program when the user inputs the caracter "|"? Here is this little super simple program:
int main()
{
int var1 = 0;
int var2 = 0;
while(cin>>var1>>var2)
... | Your loop will already exit as soon as someone enters something istream cannot << into an integer. Anyway to exit specifically at |, I would use the peek function like so:
int main()
{
int var1 = 0;
int var2 = 0;
while( cin.good() )
{
char c;
c = cin.peek();
if( c == | )
break;
el... |
5,845,428 | 5,845,458 | Console Keyboard press detection lib or standard options? | i'm making a console game but i don't want the system to wait every time i tell it to detect a press (like cin)... Does anyone know how i can get a console window to detect keyboard presses, its ok if it's just letter key detection too, i can make do!
| If it's Windows, the kbhit( ) function is the guy you want. If it's *nix, here's a kbhit( ) emulator. kbhit( ) returns immediately (no blocking) with a flag that says that there is or is not a keyboard character waiting to be read. You can test the flag to see if you should issue a keyboard read.
|
5,845,533 | 5,846,961 | Qt subclassed QStyledItemDelegate paint method is never called | Update: my paint method was not const
I have a custom QTableView connected to a QAbstractTableModel.
I recently created a QStyledItemDelegate subclass and its paint method prints a debugging message and then it calls the parent paint and then it prints another debugging message.
I have called view->setItemDelegate and ... | I think your problem is that you are not declaring your subclass's paint method as const. As such, it's not overriding the superclass method (const and non-const methods are considered to have different signatures from each other) and that's why your paint method doesn't get called.
|
5,845,534 | 5,845,555 | different types of initialization in C++ | I'm learning C++, and am rather confused as to the different types of initialization.
You can do:
T a;
which, as far as I can tell, will sometimes initialize a and sometimes won't, depending on if T has a default constructor.
You can also do:
T a(); // or
T a(1, 2, 3... args);
; (in some cases):
T a = 1; // implicitl... | You made a few mistakes. I'll clear them up.
// Bog-standard declaration.
// Initialisation rules are a bit complex.
T a;
// WRONG - this declares a function.
T a();
// Bog-standard declaration, with constructor arguments.
// (*)
T a(1, 2, 3... args);
// Bog-standard declaration, with *one* constructor argument
// ... |
5,845,810 | 5,845,921 | Constant size priority queue - Insert first or delete first? | I am using a priority_queue to store the K closest points found so far in a K-nearest-neighbor search. When I find a point closer than the point at the top of the queue, I want to pop the top element and push the new one.
if(point < pq.top()){
pq.pop();
pq.push(point);
}
Generally, is it more efficient to pop ... | If you are using std::priority_queue as your priority queue class, the standard container class std::vector is used for its underlying container class, by default.
Generally, it is less efficient to push first than pop first.
Reason one
Pushing an element in priority_queue will envoke vector::push_back which can potent... |
5,845,883 | 5,845,894 | Question about Pure Virtual Functions in C++? | I am reading some C++ text regrading Pure Virtual Functions. As the text says, the form of Pure Virtual Functions declaration, for example, is:
virtual void virtualfunctioname() = 0;
And the text explains: "Since pure virtual function has no body, the programmer must add the notation =0 for declaration of the pure vir... | If a class has any pure virtual functions, it cannot be instantiated. Also, it forces any derived classes to implement those functions, otherwise they too cannot be instantiated.
So if you remove the = 0, you'll just have a normal base class, which may be instantiated, and doesn't enforce an interface on its derived c... |
5,846,185 | 5,846,230 | How to get console text to refresh rather than re-type? | Hi so i'm making a game through the console window, and i was wondering if there was any way to just get maybe one or two text character's placement to change or disappear. Usually to accomplish this i would have to tell the console to re-type every single character and line all over again, but this just takes to long ... | You'll need to use an external library to interface with the console as C++ doesn't have these capabilities, but it is possible.
My old goto for this sort of thing is ncurses. It's straightforward, quick to set up, and cross-platform. But it's old, and its age shows. (If you're on windows you'll have to use pdcurses; s... |
5,846,233 | 5,846,241 | what can you initialize global variables to in c++ | Can you initialize global variables in c++, and if possible, what values are allowed?
| Yes, of course you can initialize globals. For built-in types, you can use any value you could use for assignment (and you can also initialize arrays, which you can't assign). For a class type, it's up to you to decide what types/values will be allowed (and/or required) when you design the class. For a pre-defined clas... |
5,846,384 | 5,846,414 | Should I use a friend class here? | I'm just getting back into C++ with a friend of mine. I'm writing a basic text based dungeon game, trying to get the player to move up, down, left and right. Well my question has two parts.
I created a Map class, a Player class and a GameLoop class. Everything that happens is obviously going inside my GameLoop. The Map... | Classes are useful because they can have methods and state/data. Generally speaking, if there is any data in your class, it's meaningless that you don't create any objects. However,
you can implement a utility class which is composed of public static functions only. In such a case you don't have to create any object.
C... |
5,846,531 | 5,846,549 | String compare in c++ | What is the difference between (x == "x") and ("x" == x) comparison in C++? Let's say x is a std::string. Is there any reason why one would be preferred over the other?
| One is a string literal "X", and the other is an instance of std::string. Some advocate having the constant "x" on the left hand side, because that way you would get a compiler error if you use assignment = instead of equality ==:
if ("x" = x) // Error! Trying to assign to const char[]
if (x = "x") // Setting the valu... |
5,846,573 | 5,846,592 | what should I do in C++ for following code in C? | what should I do in C++ for following code in C?
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
Should I use "new"?
Thanks
| Yes, you want to use new:
shared_ptr<Node> node(new Node);
You can find shared_ptr in boost, C++0x and TR1. It will handle deallocation for you, ensuring you don't have a memory leak. If you use boost, you want to include and use boost::shared_ptr.
|
5,846,691 | 5,846,719 | How to restore stdout after using freopen | I try to redirect output in my c++ program from stdout with the following:
freopen(cmd.c_str(),"w",stdout);
Then I call system to execute cmd. I have also tried forking and then calling execvp. Either way, when program control returns to my program, things written to stdout are no longer showing. How can normal b... | Do this:
fclose(stdout);
stdout = fdopen(1, "w"); //reopen: 1 is file descriptor of std output
If you can use STDOUT_FILENO from <unistd.h>, instead of 1 as first argument to fdopen.
|
5,846,934 | 5,846,948 | How to pass a vector to execvp | I want to pass a vector in as the second argument to execvp. Is it possible?
| Not directly; you'd need to represent the vector as a NULL-terminated array of string pointers somehow. If it's a vector of strings, that is straightforward to do; if it's some other kind of data you would have to figure how to encode it as strings.
|
5,847,072 | 19,001,487 | Comparing std::function<> | Is it possible to somehow compare two std::tr1::function<> objects? What if I have a collection of function<void(int,float)> objects and want to add and remove event handlers? Adding is trivial, but finding the one to be removed seems to be impossible.
| Based on information from Stack Overflow at the following link, it IS possible but only if you wrap the std::function object in its own class.
std::vector of std::function
By using a wrapper class, you can test whether two wrapped std::function pointers are equal, but that doesn't tell you anything about what the std... |
5,847,273 | 5,847,709 | order statistic implmentation | hey everybody i am trying to implement code for finding order statistic but i am getting a error ..in algorithm two variables are passed in random function is there any way to pass two variables in it if yes than how?? and if no then what can be its alternate ... your help will be appreciated
#include<iostream.h>
#i... | To select a random value between p and r, you may use this formula:
p + rand()%(r-p+1);
rand() gives you a pseudo-random integer value in [0, RAND_MAX]. Then you take the remainder (%), thus converting to a value in [0, r-p] (as long as r-p+1 is less than RAND_MAX). Adding it to p, you get a value in [p, r].
|
5,847,330 | 5,847,343 | What is the non-deprecated way to initialise a char * in C++? | When I initialise a local char * variable like so in C++:
char * pattern = "oggS";
the compiler warns me:
Foo.cpp:34: warning: deprecated conversion from string constant to ‘char*’
What is the non-deprecated way to do this in C++?
In case it matters, here's how I'm invoking the compiler (from Eclipse):
g++-4.5 -O0 -g... | You want:
const char * pattern = "oggS";
Or if you intend to change the characters in the string later:
char pattern[] = "oggS";
The first one creates a pointer-to-const-char which points to a string literal. You can't change the literal through this pointer, which is good because changing literals gives you undefine... |
5,847,334 | 5,847,388 | Compilation error when using pthread in C++ | I'm writing a sniffer class with c++ as following code.
#include "Capture.h"
#include <sys/socket.h>
#include <cstring>
#include <linux/if_ether.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <pthread.h>
Capture::Capture(int sniff_socket): sniff_socket_(sniff_socket), sniff_threadID_(0)
{
}
bool Captur... | A member function in C++ class passes this as hidden parameter, the C function pthread_create cannot understand what this is, Since static member functions dont pass this you can use a static function like this:
class Capture
{
public:
static void *sniffer_thread(void*);
};
pthread_create(..., Capture::s... |
5,847,389 | 5,847,858 | Opengl transform relative body coordinates to world coordinates | I have an opengl c++ project I'm working on, where I draw a player and a ball in his right hand. At first I want to make the ball follow the player's hand movement by setting ball position. After some time I need to make the ball travel using kinematics eqations. I get the player right hand transform matrix using (I do... | You need to transform back to the player's hand position; invert the transformation from hand to world. Since OpenGL is not a math library, you need to either implement the matrix math yourself of use some 3rd party linear math library.
EDIT due to comment:
What you transform is the velocity and acceleration into the b... |
5,847,480 | 5,847,506 | What is the C++ idiom to replace snprintf(3)? | I have some C++ code which needs to generate an error message when parsing a certain file header fails. In this case, I need to ensure that a certain 4 byte field in the header is "OggS", and if it is not, return an error message like "invalid capture_pattern: 'FooB'; expecting 'OggS'". My code looks something like thi... | You can use stringstream or ostringstreamfrom C++ Standard library. If further stream will not be used to read values from it (e.g. it's istream part won't be used) ostringstream is more suitable.
#include <sstream>
#include <string>
#include <iostream>
int main() {
std::stringstream str_stream;
int number = 5;
st... |
5,847,562 | 5,847,585 | Exception handling , unable to understand :( | Hya advance users of SO,
First of all I am new to C++, so pardon me if I don't make myself clear asking question. I've seen a example of exception handling, but couldn't figure out what's happening here :(
http://codepaste.net/zqsrnj
or
enum ErrorCode {…}; // this is exception class
ErrorCode dispatcher() {
try {
... | apifunc() and apifunc2() translate exceptions into error codes, using the dispatcher() function.
Basically, what happens is as follows:
apifunc() (and similarly apifunc2()) attempts to call a function foo(). If foo() throws an exception, then the catch block will call dispatcher() to get the error code corresponding to... |
5,847,601 | 5,849,315 | Qt - In QGraphicsScene how to find the transparent Item using itemAt? | I am trying to get gif-Item using itemAt(gif->pos()). But I am getting the underlying background image.
From Qt-Help I came to know that itemAt() will give the topmost visible item. But my problem is My item is partially visible, so when I tried to acces it by giving it's end points it yielded the back ground imgae.
C... | Use items() and pass Qt::IntersectsItemBoundingRect as ItemSelectionMode. This will test if the point touches the bounding box without testing shape.
|
5,847,639 | 5,847,749 | Simple General Questions about C++ | Ive moved from autoit and am now learning C++ and some problems keep coming up.
The first one is storing character input. The problem is that I have no idea how many characters are in that line of the file (if you are reading a file) or how many letters a user is going to type (in a console application).
What is the be... |
Investing your time in learning std::string is well worth the effort, as it takes care of a lot of hassle for you. If you don't want to take advantage of the features in C++, then why use C++ and not just C?
You can use the same code for this as you would in C.
Yes, iostream-output of C-style strings outputs until ter... |
5,847,663 | 5,847,719 | Why do I explicitly have to declare functions inline here? | Okay, up until now, I thought that functions defined in header files are treated like inline functions, just like template stuff, defined once, and all that.
I also use inclusion guards, yet I still got linker errors of multiple defined objects, and I know that is because of all those different units duplicating stuff ... | Inclusion guards only guard against the code being included twice in the same translation unit. So if you have multiple files that include the same header, the code is included multiple times. Functions defined in a header are not inline by default, so this will give you linker errors - you need to define those functio... |
5,847,671 | 5,847,779 | C++ multi-threading question | I was recently making a very simple application that just printed matrix-effect out to the console. So I made it in a very easy to use function void drawLine(int startX, int startY, int lineLength,int speed);. The problem now is that it only prints one line at a time. Of course I need to make this application multi-thr... | This problem has nothing to do with threading- or rather, this problem absolutely doesn't require threading. A simple object-orientated design should easily allow you to draw multiple lines in a frame- how do you think single-threaded games draw thousands or more of vertices in a frame?
More importantly, only recent (W... |
5,847,769 | 5,849,377 | Boost-Extension-Reflection How to fix segmentation fault error when compiling official sample not with bjam? | So I try to port some Boost.Extension samples for standart IDEs - to make tham free from BJAM and to be able to work with them in standard ways across platforms.
The sample I have trobules with now is described here. Here is my code port (library we try to load in main code file, main application, general all port ide... | There must be difference in configuration, because this is the result of my testing:
cd /tmp
svn checkout http://cloudobserver.googlecode.com/svn/branches/v0.4/ cloudobserver
cd cloudobserver/Boost.Extension.Tutorial/libs/boost/
svn co http://svn.boost.org/svn/boost/sandbox/boost/reflection/
cd ../../projects/linux-gm... |
5,847,817 | 5,852,821 | Ascending subsequences in permutation | With given permutation 1...n for example 5 3 4 1 2
how to find all ascending subsequences of length 3 in linear time ?
Is it possible to find other ascending subsequences of length X ? X
I don't have idea how to solve it in linear time.
| Do you need the actual ascending sequences? Or just the number of ascending subsequences?
It isn't possible to generate them all in less than the time it takes to list them. Which, as has been pointed out, is O(NX / (X-1)!). (There is a possibly unexpected factor of X because it takes time O(X) to list a data struct... |
5,848,041 | 5,848,067 | access to nth element of set | There is a set visited. And I wanna check all its elements from 4-th to last.
I'm trying to do something like that
int visited_pointer = 4;
for ( set<int>::iterator i_visited=visited.begin()+visited_pointer
; i_visited!=visited.end()
; i_visited++
)
and got errors with operator+.
How can I do that in the right... | That usage of operator+ is only provided for random-access iterators. set iterators are bi-directional iterators.
But the function std::advance can be used to move any iterator a certain number of places:
#include <iterator>
//...
set<int>::iterator i_visited = visited.begin();
for ( std::advance(i_visited, visited_... |
5,848,043 | 5,848,064 | A ton of errors related to messy OOP code | I'm getting loads of errors with this when I compile. Hopefully things will become clearer for me if I solve one of them (if not then I can post the rest):
'Weapon' : illegal member initialization: 'Name' is not a base or member
It has that for Name and Cost. Weapon inherits Shopable, and Shopable has Name, Cost and De... | You can only initialize members of the current class in an initialization list. Name (and Cost) are both members of the base class; they must be initialized in the base-class constructor.
The simplest way to do that is to add a constructor to Shopable:
class Shopable {
...
public:
Shopable(std::string n, int c... |
5,848,160 | 5,848,239 | To search a value and then delete object containing it from an array of objects? | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class A
{
public :
void getData(vector< A > &);
void putData(vector< A > &);
private :
int x;
char name[90];
};
vector< A > v;
void A :: getData(vector< A > &Aref)
{
cout << "id =... | My advice:
Simplify. You could have reproduced this error with much smaller code.
Post the error messages. This code does not throw an error, it fails to compile.
Read the error messages. You class `A` lacks an equality operator (`operator==`), so `find` can't act on it-- how can it know when it's found a match?
Test ... |
5,848,241 | 5,848,331 | Emulate a file pointer C++? | I am trying to load a bitmap from an archive. The bitmap class I have takes a character pointer to a filename and then loads it if it is in the same directory. The bitmap loading class is well tested and I don't want to mess with it too much. Problem is it uses a file pointer to load and do all of its file manipulation... | Check out John Ratcliff's File Interface replacement for standard file I/O. It supports the feature you need.
You'll still need to refactor the bitmap loading code to use the new interface. However, this interface supports loading from file on disk, or memory chunk in memory (as well as writing to file on disk, or to... |
5,848,264 | 5,848,339 | Why does type knowledge disappear with Boost::MPL? | I have the following code and it works fine.
#include <boost\mpl\vector.hpp>
#include <boost\mpl\fold.hpp>
#include <boost\mpl\for_each.hpp>
#include <boost\mpl\inherit.hpp>
#include <boost\mpl\inherit_linearly.hpp>
#include <iostream>
using namespace boost::mpl::placeholders;
typedef boost::mpl::vector<short[2], lon... | If you change the operator() in print to the following, probably the
code can be compiled:
struct print {
...
void operator()(T) // remove const
or
static_cast<wrap<int>const&>(generated) // add const
|
5,848,374 | 5,848,892 | Combining Objective-C and C/C++ on Mac OS X | Can I create an Objective-C library (by XCode) and use it in my C/C++ application (compiled by GCC without supporting Objective-C).
| You need to create a C or C++ interface for your Objective-C code, so you can use this interface to call the Objective-C code from your C/C++ code. Note that you can take advantage of Cocoa's toll-free bridging: e.g. you can return an NSString* and interpret it as a CFStringRef in your C/C++ code.
|
5,848,441 | 5,848,681 | C++ parse input file and copy data to an output file | I have a file called input.txt which contains a sequence of nested objects, where each object is delimited by { and }. Attributes within the objects contain a name followed by at least one white space followed by a set of parameters delimited by ( and ). A comma separates multiple parameters see below
input.txt
{
colou... | If you just want the code to copy one file to another, following code can serve. Of course there is more than one way to achieve this, as you can see.
int copy_file()
{
ifstream input("c:\\input.txt", std::ios::in|std::ios::binary);
if(!input.good())
{
// error opening input file
return -1;... |
5,848,788 | 5,849,141 | Inserting different text to another using Regular Expressions? | I've two text files. I want to take text from first one between </sup><sup> tags, and insert it to another text file between {}.
Better example (sth like a dictionary)
Text1:
<sup>1</sup>dog
<sup>2</sup>cat
<sup>3</sup>lion
<sup>1</sup>flower
<sup>2</sup>tree
.
.
Text2:
\chapter1
\pkt{1}{}{labrador retirever is..}
... | This code puts all dict items in an array, in the order they appear. The tex file is then looped and each time \pkt{num}{} is hit an item from the array is inserted.
Newlines in dict are handled and replaced with spaces (Just remove this replace in the map if you don't want this behavior). \pkt should be found as long ... |
5,848,911 | 5,849,035 | strpbrk doesn't work | char operators[] = "+-*/^(";
char* input = new char[100];
char* output = new char[100];
char* operadores = new char[100];
char* pch = input;
char* pch2 = input;
cout << "Expresion: " <<endl; cin.getline(input,100);
cout << input <<endl;
pch2 = strpbrk (pch2, operators); ... | You are confusing yourself - the program is designed to confuse.
You have both pch and pch2 pointing at the same input string - input. You call strpbrk() to find one of the operators, saving that position in pch2. You then call strtok() on pch, and it finds the character that strpbrk() just found, and writes a NUL '\... |
5,849,051 | 5,849,058 | How to compute normals of mesh? | How do you find normals of mesh in c++ directx?
| Try D3DXComputeNormals function.
|
5,849,059 | 5,849,247 | Lambda expressions as class template parameters | Can lambda expressions be used as class template parameters? (Note this is a very different question than this one, which asks if a lambda expression itself can be templated.)
I'm asking if you can do something like:
template <class Functor>
struct Foo { };
// ...
Foo<decltype([]()->void { })> foo;
This would be use... | As of C++20, this answer is now outdated. C++20 introduces stateless lambdas in unevaluated contexts1:
This restriction was originally designed to prevent lambdas from appearing in signatures, which would have opened a can of worm for mangling because lambdas are required to have unique types. However, the restriction... |
5,849,372 | 5,849,378 | Joystick in win32 application, winmm | How should I understand this documentation: http://msdn.microsoft.com/en-us/library/dd757116%28v=VS.85%29.aspx
Can I only use 4 buttons and 1 analog stick? I've got a gamepad with 12 buttons, 2 analog joysticks and one "steering cross" (POV hat?). How many of these buttons can I use with winmm?
| If you need more axis than are supported by winmm, consider DirectInput.
However, the page you linked clearly states that up to 32 buttons and 6 axes (3 2-D analog sticks) are supported by winmm. Looks like your gamepad will max out on axes, using all 6, and also use 12 out of 32 buttons.
|
5,849,457 | 5,849,668 | "using namespace" in c++ headers | In all our c++ courses, all the teachers always put using namespace std; right after the #includes in their .h files. This seems to me to be dangerous since then by including that header in another program I will get the namespace imported into my program, maybe without realizing, intending or wanting it (header inclus... | You should definitely NOT use using namespace in headers for precisely the reason you say, that it can unexpectedly change the meaning of code in any other files that include that header. There's no way to undo a using namespace which is another reason it's so dangerous. I typically just use grep or the like to make su... |
5,849,564 | 5,849,599 | Moving positions of strings in an array | int moveToEnd(string a[], int n, int pos);
Eliminate the item at position pos by copying all elements after it one place to the left. Put the item that was thus eliminated into the last position of the array. Return the original position of the item that was moved to the end. Here's an example:
string actors[5] = { ... | string save = arr[pos];
for (int i = pos; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[n - 1] = save;
|
5,849,600 | 5,849,643 | Why doesn't closing a file automatically clear error state? | When I use ifstream to read file, I loop over all lines in the file and close it. Then I try opening a different file with the same ifstream object, it still says the End-Of-File error. I'm wondering why closing the file won't automatically clearing the state for me. I have to call clear() explictly after close() then.... | The call to close may fail. When it does fail, it sets the failbit. If it reset the state of the stream, you wouldn't be able to check whether or not the call to close succeeded.
|
5,849,893 | 5,850,145 | passing array to function | i am trying to pass an array between two functions. The _data function is my array. It takes 3 parameters; the array itself, the size of the array and the file name of the array. So this function should get each element from the input file(.txt) and put it into the array, which it seems to do ok.
void _data(string data... | Several things wrong with this code:
void _data(string dataArray[], int sizeOfArray, ifstream &fin)
Names that begin with an underscore are reserved for the C++ implementation in most circumstances - don't use them in your own code unless you have read the C++ Standard fairly closely, which I suspect you have not.
i... |
5,850,047 | 5,850,057 | C++ array of pointers to structures | I have a program that has to find the shortest path (Dijkstra's algorithm), and I have decided to use an array of pointers to structures, and I keep getting this error:
In function ‘void insertNode(Node**, int)’:
TDA.cpp:14: error: cannot convert ‘Node**’ to ‘int*’ in assignment
Here is my code:
struct Node{int d... | You're ... trying to assign a pointer to an int. You can't do that.
int *pointerArray[20];
would need to be
Node *pointerArray[20];
However, when you do this:
pointerArray[i]=&(*n);
you're doing this:
pointerArray[i] = n;
Is that what you mean to be doing? You say you want to use an "array of pointers to structure... |
5,850,257 | 5,850,393 | Stored value disappears when setting a struct pointer to null in C++ | I'm writing a C++ application to do a word search across a large database of song lyrics. to start, I'm taking each word and putting it into a Word struct that looks like this:
struct Word{
char* clean;
int size;
int position;
SongId id;
Word* same;
Word* diff;
};
I have a "makeNode" function t... | The problem is probably that in cleanse, you return clean.c_str().
That pointer value ceases to be valid when clean ceases to exist, which is when the function exits. It is no longer guaranteed to point to anything, so it's pure luck that you're ever seeing the string "again" as expected.
What I suspect happens is that... |
5,850,358 | 5,850,405 | Is there a preprocessor define that is defined if the compiler is MSVC? | So I can do something like
#ifdef MSVC
//do compiler specific code here
#endif
| It's _MSC_VER. More info at MSDN and at predef.
But, be aware that some other compilers may also define it, e.g. Intel's C++ Compiler for Windows also defines _MSC_VER. If this is a concern, use #if _MSC_VER && !__INTEL_COMPILER.
|
5,850,360 | 5,850,394 | Why does std::bind() tries to copy my object? | I'm using VS2010.
In the constructor of my non-compyable Scene class I have :
auto& character_mgr = CharacterManager::Instance();
character_mgr.initialize();
character_mgr.add_observer( std::bind( &Scene::on_character_event, *this, std::placeholders::_1, std::placeholders::_2 ) );
Here add_observer is defined as ... |
It's the default behaviour.
To pass by reference, try using std::ref .
|
5,850,627 | 5,851,061 | Intercept clipboard changes | how it is possible to generally intercept clipboard changes in C++? E.g. I would like to write a Windows Service that intercepts any Ctrl-C. Is it possible? How?
Thank you in advance.
James
| What you need is a "windows clipboard hook". Google search on this term gives plenty of information, for example, this library on CodeProject, which seems to fit your requirements.
|
5,850,724 | 5,850,747 | C++ array Visual Studio 2010 vs Bloodshed Dev-C++ 4.9.9.2 | This code compiles fine in Bloodshed Dev-C++ 4.9.9.2, but in Visual Studio 2010 I get an error: expression must have a constant value. How do I make an array after the user input about array size without using pointers?
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int size = 1;
cout... | Use an std::vector instead of an array (usually a good idea anyway):
std::vector<int> array1(size);
In case you care, the difference you're seeing isn't from Dev-C++ itself, it's from gcc/g++. What you're using is a non-standard extension to C++ that g++ happens to implement, but VC++ doesn't.
|
5,850,847 | 5,850,864 | This `do..while` loop isn't working | int sc1,sc2,a=0,b=0;
do
{
printf("Give the scores\n");
scanf("%d %d", &sc1,&sc2);
//===============================================
if (sc1 > sc2)
a+=1;
else if (sc1<sc2)
b+=1;
else if (sc1==sc2)
printf("tie\n");
//===============================================
if (a>b)
printf("tea... | If I'm reading your question properly you'd like the terminating condition to be that one of the teams "a" or "b" has a score of 3. However, in your code you've written that the only way the while can loop is if one of the teams has a score of 3. You want:
while( !( a==3 || b == 3) )
|
5,851,003 | 6,623,690 | If i want event driven server what to use libevent or libev? | i want to make basic chat server using one of the event driven libarary .
but what to chose ? libevent or libev what is better ? which has better c++ support ?
which runes better in windows ?
what is faster ? faster to develop and understand
| I prefer libev. It's very minimalistic and some of the benchmarks (probably old) I've seen indicate it performs better. The documentation is also quite good.
|
5,851,075 | 5,851,226 | Problem reading a file containing decimals | Im having a problem trying to figure out why my file is returning 0's instead of the numbers inside the file, here is the code I did in C++ on reading a file:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string cfile;
int cnum1,cnum2,cnum... | Your reading and printing code appears to work, but your command line reading code may have some problems.
I ran your code without getting command line arguments. The following code, is pretty much copy-pasted from your main minus getting command line args.
int main()
{
double **matrix;
std::string file = "test... |
5,851,126 | 5,851,142 | How thread safe is this? | In my Color class, I have a private static bool which determines if a new Color should premultiply its alpha. Since this value is only ever read (and only set before any secondary threads are created), is it safe to instance 2 colors on 2 threads?
Thanks
| Reading memory from multiple threads is thread safe. Its when you're changing and reading memory at the same time that you run into troubles.
|
5,851,137 | 5,864,575 | Making DrawText break a string | So i can make drawtext break a string if the string has spaces, or if i put in \r\n at the end of the string. However, a long string that has no spaces or line breaks in it continues past the drawing rectangle and gets clipped. I would like to prevent this, if possible.
Nothing in the format flags for drawtext stood ou... | What you would normally do is use the DT_WORDBREAK flag. From the DrawText documentation on MSDN, this:
Breaks words. Lines are automatically
broken between words if a word would
extend past the edge of the rectangle
specified by the lpRect parameter. A
carriage return-line feed sequence
also breaks the lin... |
5,851,289 | 5,851,329 | Easy way to avoid clog collision from different threads? | I have a multi-threaded program where two separate threads are sending debug output to std::clog and the outputs are interspersed. I would like to find an easy way to force the output to at least be kept separate except at line feeds in the output. This way, the debug output can be more readily interpreted. In some pl... | There's no particularly easy way of doing this, and there's an extended discussion about it here: http://www.cplusplus.com/forum/general/27760/
The problem is somewhat solved there with the creation of a new AtomicStream that writes an entire line atomically, before anything else is streamed (this is done with bufferin... |
5,851,350 | 5,851,366 | Is it safe to access a default argument by reference? | I have a function that looks like this:
class SomeClass {
// ...
};
void some_function(const SomeClass& arg = SomeClass());
The function some_function accesses its argument by reference and has a default value. Is it safe to do this, or will the reference be invalid when I call the function without an argument?
| Yes, it's safe. A const reference bound to a temporary extends the life of that temporary to the lifetime of the reference. The same is true of rvalue references.
|
5,851,530 | 5,857,292 | Reinventing The Wheel: Random Number Generator | So I'm new to C++ and am trying to learn some things. As such I am trying to make a Random Number Generator (RNG or PRNG if you will). I have basic knowledge of RNGs, like you have to start with a seed and then send the seed through the algorithm. What I'm stuck at is how people come up with said algorithms.
Here is t... | First, just to clarify, any algorithm you come up with will be a pseudo random number generator and not a true random number generator. Since you would be making an algorithm (i.e. writing a function, i.e. making a set of rules), the random number generator would have to eventually repeat itself or do something simila... |
5,851,542 | 5,851,581 | Problems while making a stack in C++ with auto referenced classes | I'm making a stack in C++ to manage infix, postfix and prefix mathematical operations. I use 2 classes, one called Node (an auto referenced class) and other one called Stack. In Node I have 2 properties, one is ID (an int, only for tests) and element (is a char*). In Stack I manage all the nodes in 2 stacks, one stack ... | Each Node shall own its element value:
class Node{
private:
char element[MAXSIZE];
};
And so your constructor Node::Node(const char *element) shall make its own copy of the value - strncpy or some as such.
|
5,851,619 | 5,861,746 | recursively nested templates -- gcc bug? | I have the following snippet.
template< typename T >
struct f
{
template< typename V >
struct a : f
{};
};
int main ()
{
f<int>::a<int>::a<double> x;
}
It compiles with no warnings on GCC 4.4.5 and also MSVC 2010, but not on GCC 4.5.2 -- on which I get the following errors:
test.cc: In function 'int main()':
... | There were a couple of good notes in existing answers. First, f's type is incomplete at the time the nested class template is defined, but f is a dependent type. Now, if you instantiate the nesting template (f), it will instantiate a declaration of the nested template (the member). Note that the declaration of the memb... |
5,851,662 | 5,885,143 | What C or C++ tool is used to automatically generate WSDL in SOA project? | Suppose in fairly large SOA project I am tasked with developing Web Service in C++. I am looking for tools that would automatically generate WSDL ((both REST and SOAP))and XML Schema for this web service that I have implemented in C++ resulting in several classes and their methods.. Are there such tools that would co... | gsoap is a soap framework for C/C++. It comes with a nice tool that completely automates he task of creating the wsdl files from a header file.
|
5,851,890 | 5,851,910 | How to set QLabel's size to that of the image in its pixmap? | I am using QT for my application, and ended up using QLabel to display image. However, it is displayed cropped.
How can the size of QLabel set to one of its pixmap? How can that be done in such a way that it would change if the pixmap changes?
| // Call this function whenever you want to change the label's pixmap
void SetPixmapLabel(QLabel * myLabel, const QPixmap & pixmap)
{
myLabel->setPixmap(pixmap);
myLabel->setFixedSize(pixmap.size());
}
|
5,852,046 | 5,852,053 | if (aCHAR == 'character' || 'another character') problems | Hi so i'm trying to check a certain character in a string to make sure it's not a \,=,|, etc. and replacing the space with the "player" character if it's not but the function is returning true everytime, even if char newLoc is equal to '' (empty):
screen.get_contents returns a vector container full of strins, and
sprit... | You need:
if (newLoc == '|' || newLoc == '/' || ...)
What you have written is equivalent to:
if (newLoc == ('|' || '/' || ...))
which is equivalent to:
if (newLoc == 1)
Note that a cleaner way of writing this might be:
switch (newLoc)
{
case '|':
case '/':
...
return true;
default:
return false;
}
|
5,852,057 | 5,859,484 | Ubuntu + qt, how to update? | Installed qt from ubuntu software center then can't find examples with qml, checked version, it shows that Using Qt version 4.6.2 in /usr/lib.
My question, how to update qt creator and qt?
Is there any button on qt creator or function in make or qmake to update from 4.6.x to 4.7.xxx?
If I will download new version fro... | Either update your ubuntu to 10.10 or 11.04 or use this ppa, which contains Qt 4.7.0
deb http://ppa.launchpad.net/kubuntu-ppa/backports/ubuntu lucid main
|
5,852,237 | 5,852,254 | question on c++ recursion and local variables | suppose I have this recursion:
void doSomething(double j)
{
double x;
double y;
x = j -1;
y = j -2 ;
doSomething(x+y);
x = j + 31;
y = j + 12 ;
}
I know that this recursion executes infinitely, but just ignore that
My question is with regards to variables x and y's scope in the recursion... |
will x and y's scope be valid only for the function in that specific stage in the recursion tree?
Yes.
when I call doSomething() again, and the child doSomething() in the recursion tree, redeclares x and y, will it reset the parents' x and y variables as well
No.
is it creating an entirely new x and y variables t... |
5,852,240 | 5,852,468 | XCode import statement and subdirectories | I'm running into an import issue that as a relative newcomer to the Objective-C/C++/XCode world I haven't seen before.
I'd like to include this library with my project: https://github.com/jdkoftinoff/jdksmidi
But, it seems like no matter how I try to add it to the project, I get errors when I try to import:
#import "jd... | You probably need to adjust your User Header Search Paths (USER_HEADER_SEARCH_PATHS) in your build settings. Make sure that the folder containing jdksmidi is in the path. Hope that helps.
|
5,852,304 | 5,852,332 | My makefile isn't finding my include paths | Simply put: It's not finding the include paths:
CC = g++
OBJS = *.o #*/*.o
DEBUG = -g
PNAME = game
INCLUDES = -Iheaders
CFLAGS = -Wall $(DEBUG)
LFLAGS = -Wall -lsfml-graphics -lsfml-window -lsfml-system $(DEBUG)
all: build
build: $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o $(PNAME)
clean:
\rm *.o *~ $(PNAME)
.cpp:... | Your makefile looks pretty broken to me. Firstly, you probably want:
OBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
Secondly, your final rule needs to be something more like:
%.o: %.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c $^ -o $@
|
5,852,385 | 5,852,550 | Console Keyboard hit detection and interpretting | Hey so it's been reccomended to me that i should use the kdhit() function to detect a keypress in a console window:
"If it's Windows, the kbhit( ) function is the guy you want. If it's *nix, here's a kbhit( ) emulator. kbhit( ) returns immediately (no blocking) with a flag that says that there is or is not a keyboard c... | Use _kbhit() to test if a key is pressed. and when it is use _getch() to get the value. (note _getch() can return 0 or 0xE0 for special keys and call _getch() again for that value)
for displaying the characters while reading use _getche().
|
5,852,437 | 5,853,282 | libgcrypt AES to return ascii ciphertext? | Hey, I m developing a JNI shared library which uses AES256 CFB mode to encrypt some data using libgcrypt and then passing the encrypted the data back into java app for further processing.
However, when I try to decrypt the data by passing it again to the shared library I can no longer get the original plain text back. ... | Why are you using JNI and external libraries just to encrypt a string? Use Java's built-in javax.crypto.Cipher class.
However, regarding your actual question, you should be passing the data as a byte array, not a string. Ciphers operate on bytes, not abstract Unicode codepoints.
|
5,852,742 | 5,953,308 | How to use libusb with libevent? | I'm writing an event-driven application using libevent, and I need to do a USB transfer using libusb-1.0.
I wanted to use libusb_get_pollfds to get a list of files descriptors (in fds) and add them to libevent like this:
const struct libusb_pollfd **fds = libusb_get_pollfds(device->context);
const struct libusb_pollfd... | I found an error in code. It should have been:
const struct libusb_pollfd **it = fds;
for(;*it != NULL; ++it) {
cout << "Adding fd: " << (*it)->fd << ", " << (*it)->events << endl;
struct event * ev = event_new(base_,
(*it)->fd, (*it)->events | EV_PERSIST,
callbacks::libusb_cb, this);
even... |
5,852,762 | 5,852,783 | Changing ifstream to Integers (after being loaded from a .txt file) C++ | Okay, so, I have a couple text files that are written to and read from in my program, they are loaded using:
here is one of the four
ifstream xps;
and then loaded using:
xps.open ("xp.txt", fstream::in | fstream::app);
Inside of xps is a number, and I would an integer (called xp) to load this number.
So how would I g... | Do you just want to read the integer from the file? If so, all you have to do is use operator >> from the ifstream class:
int xp;
xps >> xp;
And then xp will hold the number from the file.
You can do the same thing with different types as well, such as chars, floats, strings, etc.
|
5,852,808 | 5,863,349 | Floating/Always above dialog | I've noticed in GIMP that when a dialog is opened it does not disable the parent window. The parent window can still be used, while the child window floats in front of it.
I want to do the same thing, how ever for me when I click on my parent window it pushes the children to the back, such that the parent comes to the ... | Looks like I didnt have parenting setup correctly on my dialog! It needed to be parented to the parent dialog/main window and then it just works.
|
5,852,815 | 5,852,823 | Why does this double to int conversion not work? | I've been thoroughly searching for a proper explanation of why this is happening, but still don't really understand, so I apologize if this is a repost.
#include <iostream>
int main()
{
double x = 4.10;
double j = x * 100;
int k = (int) j;
std::cout << k;
}
Output: 409
I can't seem to replicate th... | 4.1 cannot be exactly represented by a double, it gets approximated by something ever so slightly smaller:
double x = 4.10;
printf("%.16f\n", x); // Displays 4.0999999999999996
So j will be something ever so slightly smaller than 410 (i.e. 409.99...). Casting to int discards the fractional part, so you get 409.
(If ... |
5,852,923 | 5,855,678 | Automatically add files to be compiled in visual studio | I am using Visual Studio 2010 to build an application in C++. I have a custom build event which creates additional headers and source files in a separate directory. How can I tell Visual Studio to include those generated files in its build queue. I don't necessarily need to add them to the project but I need to compile... | I don't think it's possible (unless there's an add-on for that or something). But what you could do is to generate all those files and then add them to the project. After that in the custom build event specify them as outputs. That way VS will not try to build them before they are generated and will not complain tha... |
5,852,982 | 5,852,993 | Should I use returning functions when the return value isn't needed? | I have a function that looks like this:
int Game::GetInput() {
while (true) {
// do stuff
if (something) {
// do this
return 0;
}
else {
// do other stuff
}
}
}
I'm wondering if it is common or proper to have a returning function, rat... | Just make your function void, and simply return?
// vv void return type
void Game::GetInput() {
while (true) {
// do stuff
if (something) {
// do this
return; // <<<< No return value
}
else {
// do other stuff
}
}
}
|
5,853,052 | 5,853,076 | How to initialize static function pointer with non-static class function when class initing? | Definition(Core.h):
static int (*foolink)(int*, char*, key*, key*);
Also redefined in Core.cpp. This code causing error:
foolink = this->step;
error:
Engine/Core.cpp:31: error: argument of type 'int (Core::)(int*, char*, key*, key*)' does not match 'int (*)(int*, char*, key*, key*)'
Pointer using:
(*foolink)(NULL, N... | In C++ programs, most functions are member functions; that is, they are part of a class. You are not allowed to use an ordinary function pointer to point to a member function; instead, you have to use a member function pointer.
In your case, you can define it as
v you have to name the class here
int (YourClass::*f... |
5,853,080 | 5,853,084 | Can't return value from function? | I wrote this code and there is a problem that I can't seem to work out. The function is supposed to return T1 and cout it from the main but it always gives me an error "T1 is undeclared identifier". Why?
#include<iostream>
#include<math.h>
#include<time.h>
using namespace std;
double factorial()
{
int i;
double ... | You have to define T1 first locally or make it a global variable (not recommended).
int main()
{
double T1=factorial();
cout<<T1<<endl;
return 0;
}
|
5,853,186 | 5,853,295 | Conversion of lambda expression to function pointer | This is a follow up question to this question: Lambda how can I pass as a parameter
MSDN supposedly has marked the item as fixed. I took a look at the specifications, but I'm having trouble converting their specifications into what the syntax should be.
So for example:
void printOut(int(*eval)(int))
{
for(int x = 0... | There is no syntax per se, it's an implicit conversion. Simply cast it (explicitly or implicitly) and you'll get your function pointer. However, this was fixed after Visual Studio 2010 was released, so is not present.†
You cannot make a capture-full lambda into a function pointer ever, as you noted, so it's the functi... |
5,853,206 | 5,853,238 | What are some advantages to the different programming languages? | I have always had an interest in coding, and a while back a started to learn C#. Since I only do this as a hobby, i have been learning it very slowly and don't know too much yet, but when I started to read about C++ and how it runs closer to the OS, I started to wonder if I should start learning C++ instead. I know htm... | As a person who has done all of these languages professionally, I would say that C# is probably the easiest to learn while still being very powerful. There is a lot of help for the .NET platform both from the libraries standpoint and from the community as well. Unless you really want to get down and dirty with a lang... |
5,853,216 | 5,853,340 | how to convert this? | hi may i know how to convert this c++ code to c#?
memset(device, 0, 32);
I tried the following :
device = new string(Char(32));
Is this correct?
| well, basically, in c#, you can simply say :
string device = string.Empty;
in fact, you can even say:
var device = string.Empty;
At this point, device is initialized as a pointer to a string variable who's current value is string.Empty or "", with whatever amount of memory c# decides that it needs. The amount of mem... |
5,853,246 | 5,853,262 | How much "data" you can put into a string? | As programmers, we work with strings a lot. Most of the time, I use them without thinking about them too much. Lately though, I have been using strings to return copious amounts of information from a function with no problem. My latest example is a binary tree with 10's of 1000's of entries. I have a recursive func... |
The real limit on the size a string object can reach is returned by member max_size.
from here.
Link specific to max_size
So yeah, it's implementation-specific.
|
5,853,378 | 5,853,392 | need to help to convert | Hi need help to convert this C++ code to C#
sprintf((char *)(dataBuffer), "Failed statistics read, device %s", device);
The dataBuffer is byte[]
I wrote this, but with error converting string to byte[]
dataBuffer = string.Format("Failed statistics read, device {0}", device);
| String str = string.Format("Failed statistics read, device {0}", device);
byte[] dataBuffer = System.Text.Encoding.ASCII.GetBytes(str);
// for 2-byte unicode
byte[] dataBuffer = System.Text.Encoding.Unicode.GetBytes(str);
// for UTF8 unicode
byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(str);
|
5,853,393 | 5,853,413 | c style string on c++ question | so you can do c style string on c++ using char * ...
my question is, can you pretty much do anything you can do on normal string with such declaration..
so suppose you have
char * c;
can you do:
c = "etcetc";
c = c + "dddddd";
etc?
and moreover is it pretty much interchangable with string?
so
char * c = "etcetc";
s... | A C-style string is essentially a NULL terminated character array while std::string in C++ is an well-designed object-oriented string class/object. In most case, they're NOT interchangeable and it depends on what operation you perform. You can always call std::string::c_str() to get the internal C-style string.
char * ... |
5,853,469 | 5,853,549 | changing value from function | I want to change a 2dim char array in a function.
I allocate the space like
char **u;
u = new char * [ MAX_DEPTH ];
for (i=0; i<MAX_DEPTH; i++)
u[ i ] = new char [ BUFFER_SIZE ];
the function looks like
rem(char ***arr, int max_length, char *url)
{
int idx=0;
char * p;
int i;
p = strtok (url,"/");... | You need to change the reference to tmp in your function, to arr. You aren't accessing the parameter arr at all. Also, you do not need char *** here, since you aren't changing the space allocated to u. Instead, you should have parameter char **arr, which you access as arr[i][j]. And you should then pass u to rem, r... |
5,853,476 | 5,853,706 | Homework - Operator-Overloading Currency Class - Stuck/Lost | I need help with creating Operator-Overloaded functions please. I tried 2 but I am stuck.
(Thank you all for your help last time! I was able to completely finish :] ).
Problem 1:
The operator+(const Currency &rhs) will add the 2 dollar amounts, but not the 2 cent amounts, though it keeps the cents from one of them. So,... | Okay, now that we have little enough code to really look at, a few suggestions. First, I think I'd have only one addition operator:
Currency operator+(Currency const &c);
Have that add both the dollars and cents of the right side, and return the result. It might be even better to use a global operator overload, if you... |
5,853,607 | 5,853,904 | How to use GetDHtmlDocument() in MFC programming? | I am trying to use
HRESULT
GetDHtmlDocument(IHTMLDocument2
**pphtmlDoc);
function in MFC programming.
Basically, I am trying to render GUI in a HTML View Dialog application (C++ w/ MFC) given different configuration (loading input).
So I put following code in a OnInitDialog() function.
BOOL CSampleProgramDlg::On... | Your calling to GetDHtmlDocument() and GetElement() will return E_NOINTERFACE.
According to my knowledge, you are not always guaranteed to have html document completely loaded when you're performing in CDHtmlDialog::OnInitDialog().
Instead, you should override CDHtmlDialog::OnDocumentComplete() in CSampleProgramDlg. It... |
5,853,797 | 5,853,839 | Best way to make a multidimensional array odd-dimensioned in C++? | I wrote the following function to make a 2-D array object odd-dimensioned by adding a row or column as needed (where sizeX, sizeY, get, set, and resize are self-explanatory grid2D member functions).
void makeOdd(grid2D<double> *pSrc)
// -----------------------------------------------------------------------------------... | I think it would be easier to check the number of rows first, and extend it by 1 if needed. Then, check the number of columns, and extend each of them by 1 if needed.
Assuming your grid2d is a wrapper around a vector<vector<T> >, you can pass a value to resize that it will use to fill the newly created space, so when y... |
5,853,833 | 5,853,848 | casting non const to const in c++ | I know that you can use const_cast to cast a const to a non-const.
But what should you use if you want to cast non-const to const?
| const_cast can be used in order remove or add constness to an object. This can be useful when you want to call a specific overload.
Contrived example:
class foo {
int i;
public:
foo(int i) : i(i) { }
int bar() const {
return i;
}
int bar() { // not const
i++;
return con... |
5,853,855 | 5,853,876 | How to deal with unterminated character arrays when building C++ strings? | As noted in What is the C++ idiom to replace snprintf(3)?, I'm parsing a file header and building an error message if a certain four-byte field in the header is corrupt. This code sums up what I'm trying to do:
const std::string parseCapturePattern(const int fd) { // fd is the descriptor of the ogg file
const char CA... | std::string(capture_pattern, capture_pattern+4) will construct a string from the 4 first characters of capture_pattern.
|
5,853,912 | 5,853,938 | what does this notation mean in c++ | so I have:
char inBuf[80]
and then there's another line
inBuf+9
what does it mean when I add that +9 to the array's name?
| It is same as referencing element number 9(0 based).
An equivalent notation would be:
&inBuf[9]
If you want to get the value, you could use *(inBuf+9)
|
5,853,927 | 5,853,957 | iPhone Application Development on Windows | As I've seen many questions related to this topic but this is a completely different question. I wanted to ask if there is any header file or anything else which will help me to program iPhone Application on Windows using Visual C++ 2008 and then test it on my phone (and not really make it open to the real market) ?
| Unfortunately there isn't any way to develop native iphone applications on Windows. OS X is required to develop iOS applications.
There are third party tools, such as Corona, and Monotouch, which will allow you to write you application in languages other than objective-C, but in order to test in the simulator or on a p... |
5,854,317 | 5,854,328 | What is the difference between these (bCondition == NULL) and (NULL==bCondition)? | While exploring msdn sites ,most of the condition checking places they are using (NULL == bCondition).
what is the purpose of using these notations?
Provide some sample to explain these please.
Thanks.
| The use of NULL == condition provides more useful behaviour in the case of a typo, when an assignment operator = is accidentally used rather then the comparison operator ==:
if (bCondition = NULL) // typo here
{
// code never executes
}
if (NULL = bCondition) // error -> compiler complains
{
// ...
}
C-compiler g... |
5,854,438 | 5,857,890 | windows mobile put call on hold programmatically | I need to put on hold calls programmatically on windows mobile device. Other operations as answering or rejecting call I accomplish simulating key presses.
Using the user interface of the phone, first I have to answer the phone, then put it on hold.
Is there any way to do this programmatically preferably in c# (or c+... | I believe RIL_ManageCalls() with the RIL_CALLCMD_HOLDACTIVE_ACCEPTHELD will do that. You will need to use P/Invoke to do this in C#.
If you prefer TAPI, then try lineHold.
-PaulH
|
5,854,910 | 5,855,014 | How to sleep an APR thread? | I am using APR library to create portable multi-threading program in C++. Problem is I need to sleep a thread when it is not needed but there is no function mentioned in manual to do so.
Do you now a way how to sleep an APR thread without need to use native system functions? I would like to avoid any OS specific code.
... | If you simply want to hand over CPU to other thread, you can use:
void apr_thread_yield(void);
Otherwise, you can use:
apr_status_t apr_thread_cond_timedwait(
apr_thread_cond_t * cond,
apr_thread_mutex_t * mutex,
apr_interval_time_t timeout
);
or
apr_status_t apr_thread_cond_... |
5,854,980 | 5,855,263 | Dealing with chars outside ASCII range | I have a look up table for isAlpha.
for (int i = 0; i <= UCHAR_MAX; ++i)
p.isalphaLUT[i] = isalpha(i);
where isalphaLUT is a char array...The problem is isalphaLUT[i] where i is a character outside the ASCII range, (it prints 4294967168 when i attempt to get the equivalent ASCII value). I tried setting all ASCII ra... | The correct way to test if a character is a letter is to test that it is in one of the letter categories: Lu, Ll, Lt, Lm, or Lo. You can use the ICU library from IBM to do this, it is a quite popular library for handling Unicode.
http://icu-project.org/apiref/icu4c/uchar_8h.html
You can also use the u_isalpha function... |
5,855,046 | 5,855,068 | Can constructor be called from static functions? | I am sorry if this question has been asked before (I tried to find it but in vain).
I was going through Singleton design pattern at http://sourcemaking.com/design_patterns/singleton/cpp/1 (code is copied from there)
class GlobalClass
{
int m_value;
static GlobalClass *s_instance;
GlobalClass(int v = 0)
... | You can call a constructor from anywhere. If you couldn't call a constructor without an instance, how would you get any instances in the first place?
You've probably called them from plain functions countless times. Static functions are no different.
|
5,855,147 | 5,855,212 | Run-Time Check Failure #2 - Stack around the variable 'positions' was corrupted | Im having a problem returning a structure. It says Run-Time Check Failure #2 - Stack around the variable 'positions' was corrupted and i have no idea why. I have to finish this by tonight to proceed with the rest of the project. Do help if you know. thank you :)
struct Position
{
int SrcDstScore[50][5];
char pi... | In the initial loop, you're indexing in to SrcDstScore and pieceColor using indexes 1 to 5 and 1 to 2 respectively. These should be indexes 0 to 4 and 0 to 1.
The same applies further down, on this line and the three after it:
positions.SrcDstScore[counter][1]= Row;
And in the two instances where you have positions.S... |
5,855,200 | 5,855,254 | Performance measuring with prof | Is there a way to run linux's prof in a way equivalent to what a program with -gprof would do? I know wouldn't be exact, but only statistically correct.
I'm basically looking for a way to do a gprof-like analysis on a C/C++ program that includes debug symbols, but without recompiling it.
| I'm very satisfied lately by CPU profiler of the Google performance tools. Programs basically run at undistorted normal speed under it. No recompilation is required, linking against a special libraries is recommended but using LD_PRELOAD is also possible in most cases.
|
5,855,399 | 5,855,588 | OpenXML SDK C++ Examples | HI,
I'm trying to create a word document in C++ using OpenXML SDK,
I'm facing problems in adding references and using namespace as most of the examples in the web are given based on C#.
1.How do I add references to project and also use namespaces(Ex - using namespace System.Xml;) in the code
Also please suggest any ... | I don't know of any for the SDK, but if you're looking for C++ in .NET and working with Open XML (System.IO.Packaging, etc.), grab the C++/CLI samples and lab off of the Open XML Developer workshop content page. In fact, all the other stuff there is also very helpful in working with Open XML.
|
5,855,420 | 5,855,433 | character chart needed | Hi i would like to convert 0x49 and 0x83 from C++ to C#.
May i know what does this 0x49 represent in c# character?
Also, what does 83 represent in character?
I have searching through google but found no answer for this. I would appreciate it there is a chart outthere list out all the ASCII code representing the charac... | Have a look here. But ascii is ascii.. there are no differences between C++ and C#
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.